Intervention \ Image \ Exception \ NotWritableException无法将图像数据写入路径

问题描述 投票:0回答:2

我正在尝试将图像放置在比带有时间戳记生成的文件夹中。这给了我标题的错误。

Intervention \ Image \ Exception \ NotWritableException无法将图像数据写入路径(/Users/me/Sites/test/public/uploads/images/1573905600/title-1.jpg)

这是我的代码:

    $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



            }


        }

    }

我做错了什么?

谢谢

laravel intervention
2个回答
1
投票

检查此文件夹是否已创建。然后授予其写权限

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

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

0
投票

检查此行代码$ newPhotoName = Str :: slug($ request-> get('titre')。“-”。$ i,“-”)。“。jpg”;

是否应该是$ newPhotoName = Str :: slug($ request-> get('title')。“-”。$ i,“-”)。“。jpg”;

我的意思是$ request-> get('title')而不是$ request-> get('titre')。

OR

您可以根据请求验证从刀片中检出您的输入名称,如果模型相同,也可以填写模型。

我希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.