php - 如何修复“无法将图像数据写入路径”Laravel 6.X
问题描述
我创建了一个媒体类来上传图像以存储在 Laravel 的存储公共路径中,但干预保存方法不起作用
我试图更改目录的权限,但没有。我还尝试对我的路径使用 public_path() 函数,或者对文件使用 getRealPath() 函数。我还检查了与此问题相关的许多其他类似问题,最后我认为这可能是 Laravel v.6 的问题
这是上传文件的功能:
/**
* @param $entity
* @param $file
* @return string
*/
public function processFile($entity, $file)
{
if (!$file->isValid()) {
return false;
}
$imgName = preg_replace('@[a-z0-9]i@', '_', md5(uniqid(time())) . time());
$fileName = $imgName . '.' . $file->extension();
$pathSmall = "image/$entity/small/";
$pathLarge = "image/$entity/large/";
if (!Storage::exists($pathSmall)) {
Storage::makeDirectory($pathSmall, 7777, true, true);
}
if (!Storage::exists($pathLarge)) {
Storage::makeDirectory($pathLarge, 7777, true, true);
}
Image::make($file)->resize(310, 170)->save($pathSmall.$fileName);
Image::make($file)->resize(1920, 1080)->save($pathLarge.$fileName);
return $fileName;
}
我试图调试所有代码,问题是保存方法,图像制作和调整大小正确但保存不起作用:
Intervention\Image\Exception\NotWritableException: Can't write image data to path (image/post/small/c2839f74e99f1c7f7c798171cf8ecf7b1571167248.jpeg) in file /home/vagrant/code/api-blog/vendor/intervention/image/src/Intervention/Image/Image.php on line 150
解决方案
推荐阅读
- c++ - C++ 程序在第一次尝试时会给出垃圾,但如果它捕获异常并重试,则会给出正确的值
- wpf - 如何获取用户控件中元素的位置
- javascript - 有没有办法在使用 php 的浏览器中使用 ajax 或类似方法来抓取呈现某些数据的页面
- android - Python/Kivy 应用程序到 Windows 上的 apk - 安装虚拟机后该怎么办?
- android - 打盹模式与网络状态
- angular - 如何获得增量后数字的总值
- json - 在 React-Native 中访问 Json 对象数组
- angular - ionic3 通过 `radio` 更改页面数据
- c# - 将事件设置为数组c#中的对象
- python - 句子含义相似度和频率