Laravel “拉雷维尔”;Can';t将图像数据写入路径({$path})";

Laravel “拉雷维尔”;Can';t将图像数据写入路径({$path})";,laravel,file-permissions,laravel-6,directory-permissions,Laravel,File Permissions,Laravel 6,Directory Permissions,我在Ubuntu18.4上创建了Laravel项目 我在/var/www/html/中上传我的项目,在home/sun/download/中上传图像 运行此代码后: $imageName = "thumb_{$size}.{$extension}"; $routePath = $url . '/products/' . $product->id . '/'; Image::make($file->path())->resize($size, null, function ($

我在Ubuntu18.4上创建了Laravel项目

我在
/var/www/html/
中上传我的项目,在
home/sun/download/
中上传图像

运行此代码后:

$imageName = "thumb_{$size}.{$extension}";
$routePath = $url . '/products/' . $product->id . '/';

Image::make($file->path())->resize($size, null, function ($constraint) {
            $constraint->aspectRatio();
        })->save($routePath, $imageName);
显示此错误:

"Can't write image data to path (/home/sun/download/products/2/)"

如何解决此问题?

权限问题,您是否尝试过使用存储外观

$Image->save(存储::磁盘(“您的磁盘”)->路径($routePath),$quality);

这就是我在自己的情况下存储图像的方式

Image=Image::make($source);
$Image->getCore()->stripImage();
#调整图像大小并保存
$Image->fit($width、$height、function($constraint){
$constraint->upsize();
});
返回$Image->save(存储::磁盘('public')->路径($destination),$quality);

请解释更多如果您在项目外部写入图像,您需要检查运行laravel的用户是否有权限写入该目录(操作系统问题不是laravel本身),使用laravel提供的存储外观将作为快速解决方法,但它会将您的数据存储在您的laravel应用程序的
/var/www/html/storage/…
中,它可以在其中写入文件,因为该存储文件夹具有755/644权限,因此,如果您想在Laravel文件夹外存储文件,您需要查看的是linux文件夹许可证。我需要上传到
home/sun/download/
我建议的新标签会有所帮助