Cannot save image tampering image. NotWritableException in Image.php 138 line

I am trying to save a managed image that I click on s3.

My code that works This code saves the image directly in the public folder *

public function store(Filesystem $filesystem) { $request = Input::all(); $validator = Validator::make($request, [ 'images' => 'image' ]); if ($validator->fails()) { return response()->json(['upload' => 'false']); } $postId = $request['id']; $files = $request['file']; $media = []; $watermark = Image::make(public_path('img/watermark.png')); foreach($files as $file) { $image = Image::make($file->getRealPath()); $image->crop(730, 547); $image->insert($watermark, 'center'); $image->save($file->getClientOriginalName()); } } 

What I would like to achieve is to save it in my own folder. First, what is the best place to store an image for a blog post in a repository from a public folder? But anyway, when I do this:

 $image->save('blogpost/' . $postId . '/' . $file->getClientOriginalName()); // Or this $image->save(storage_path('app/blogpost/' . $postId . '/' . $file->getClientOriginalName())); 

I get an error message:

in the public

NotWritableException on Image.php 138 line: cannot write image data to path (blogpost / 146 / cars / image.jpg)

or

storage path

NotWritableException on Image.php 138 line: it is not possible to write image data to the path / code / websites / blog / storage / app / blogpost / 146 / image.jpg

I tried

 cd storage/app/ chmod -R 755 blogpost 

And it still doesn't work

Thanks for reading this.

+8
source share
5 answers

So, here is how I solved it, I first made a directory before storing,

 Storage::disk('local')->makeDirectory('blogpost/' . $postId); 

Once the folder is created, I continue to store managed images as follows:

 $image->save(storage_path('app/blogpost/' . $postId . '/' . $imageName)); 

And then clicking the image on S3

 $filesystem->put('blogpost/' . $postId . '/' . $imageName, file_get_contents(storage_path('app/blogpost/' . $postId . '/' . $imageName))); 

It worked

+5
source

You can solve this by Intervation/Image variable to the data stream using the stream function. Then use the Storage Laravel facade to save the image.

 $img = Image::make('path-to-the-image.png')->crop(...)->insert->stream('jpg', 90) Storage::put('where_I_want_the_image_to_be_stored.jpg', $img); 
+6
source

Laravel 5 needs write permission to the entire Storage folder, so try the following,

 sudo chmod 755 -R storage 

If 755 does not work, try 777 .

+3
source

Better answer @Amol Bansode.

You get this error because the $postId folder $postId not exist in the path you specified.

You can do it as follows:

 //I suggest you store blog images in public folder //I assume you have created this folder `public\blogpost` $path = public_path("blogpost/{$postId}"); //Lets create path for post_id if it doesn't exist yet eg `public\blogpost\23` if(!File::exists($path)) File::makeDirectory($path, 775); //Lets save the image $image->save($path . '/' . $file->getClientOriginalName()); 
+2
source

In my case, I transferred the project from Windows 10 to Parrot (Debian- Linux ), and I had the same problem and it turned out that the slashes were backslashes, and Linux interpreted them differently. Unlike Windows, this is not a big deal.

 Windows Code: $image_resize->save(public_path('\storage\Features/' .'Name'.".".'png')); Linux Code (Working): $image_resize->save(public_path('storage/Features/' .'Name'.".".'jpg')); 
0
source

All Articles