Intervention\Image\Exception\NotWritableException Can't write image data to path

前提是你 提交于 2020-01-25 06:41:29

问题


I'm trying to put a image on a folder than i generate with a timestamp. This give me the error in the title.

Intervention\Image\Exception\NotWritableException Can't write image data to path (/Users/me/Sites/test/public/uploads/images/1573905600/title-1.jpg)

This is my code :

    $photoPaths = $request->get('photo_paths');
    if (isset($photoPaths)){
        $photos = explode(';', $photoPaths);

        $path = storage_path('tmp/uploads/');
        $newPath = public_path('/uploads/images/').strtotime('12:00:00')."/";

        $arrayPhoto = array();


        foreach($photos as $photo){

            $photoPath = $path . $photo;


            if (File::exists($photoPath)) {

                $newPhotoName = Str::slug($request->get('titre')."-".$i,"-").".jpg";
                $newPhotoFullPath = $newPath . $newPhotoName;

                $photo = Image::make($photoPath);
                // $photo->resize(1400, 1050);
                $photo->resize(null, 1050, function ($constraint) {
                    $constraint->aspectRatio();
                    $constraint->upsize();
                });
                $photo->encode('jpg', 85);

                if(!Storage::disk('public')->has($newPath)){
                    Storage::disk('public')->makeDirectory($newPath); //It seems it doesn't work
                }


                $saved = $photo->save($newPhotoFullPath); //Create the Exception



            }


        }

    }

What i am doing wrong ?

Thanks


回答1:


check this that this folder is already created or not. then give it permission to write

sudo chmod -R 666 /public/upload/images //give permission your choice either it 666 or 775 or 777

and

$newPath = public_path('/uploads/images/').strtotime('12:00:00')."/";
            if (!file_exists($newPath)) {
                mkdir($newPath, 0755);
            }



回答2:


Check out this line of code $newPhotoName = Str::slug($request->get('titre')."-".$i,"-").".jpg";

is it suppose to be $newPhotoName = Str::slug($request->get('title')."-".$i,"-").".jpg";

I mean $request->get('title') instead of $request->get('titre').

OR

You can check out your input name from blade against your request validation and also your model fillable if they are same.

I hope this helps.



来源:https://stackoverflow.com/questions/58891527/intervention-image-exception-notwritableexception-cant-write-image-data-to-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!