现有的可写目录仍被Intervention Image标记为“不可写”

时间:2018-07-06 13:43:17

标签: php laravel permissions upload intervention

我希望能够即时上传图像并调整其大小。一开始,我有以下代码:

private function uploadFile($file, $category_id) {
    $filename = $file->getClientOriginalName();
    $path = $file->storeAs("public/category/$category_id", $filename);
    return '/' . str_replace('public', 'storage', $path);
}

但是,由于Laravel“ vanilla”无法处理图像大小调整,因此我不得不安装Intervention的Image及其执行几乎所有操作的能力。

我想到了以下代码:

Image::configure(array('driver' => 'imagick'));
$path = "public/category/38";
Storage::makeDirectory($path, 493, true);
if(is_writable(storage_path('app/'.$path))) {
    $image = $img = Image::make($file);
    $image->resize(null, 400, function ($constraint) {
        $constraint->aspectRatio();
    })->save(storage_path('app/'.$path));
}

由于Intervention无法处理目录的生成,因此我确保自己创建目录,并且在告诉Intervention创建图像时将重点放在了

但是,在出现“ NotWrittableException”错误且可写时,我不断收到该错误。

我该如何解决这个问题?

提前谢谢

0 个答案:

没有答案