Intervention \ Image \ Exception \ NotWritableException无法将图像数据写入路径 [英] Intervention\Image\Exception\NotWritableException Can't write image data to path

查看:77
本文介绍了Intervention \ Image \ Exception \ NotWritableException无法将图像数据写入路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 无法将图像数据写入路径(/Users/me/Sites/test/public/uploads/images/1573905600/title-1.jpg)

Intervention\Image\Exception\NotWritableException Can't write image data to path (/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



            }


        }

    }

我做错了什么?

谢谢

推荐答案

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

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

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

这篇关于Intervention \ Image \ Exception \ NotWritableException无法将图像数据写入路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆