如何修复“无法将图像数据写入路径” Laravel 6.X

时间:2019-10-16 16:56:45

标签: php laravel intervention

我创建了一个Media类来上传图像以存储在Laravel的Storage公共路径中,但是干预保存方法不起作用

我试图更改目录的权限,但没有任何更改。我也尝试对路径使用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

0 个答案:

没有答案