Laravel Windows 的权限以保存在 Public 路径中

Laravel Permissions on Windows For Saving in Public Path

我正在使用干预图像将图像保存到 laravel 项目中的 public 路径。我的代码如下

Image::make($image)->resize(300, 300)->save( public_path($path . $filename ) );

我已确保该目录存在但仍然收到错误 Intervention \ Image \ Exception \ NotWritableException Can't write image data to path 我找到了多种方法在 linux 环境中使用 chown 解决此问题,但是我看到 none 用于 windows。我该如何解决这个问题?

该错误并不意味着您需要许可,尤其是在 windows 环境中

这意味着您发送了无效的路径参数(目录不存在)

让我们这样说 $path

$path = 'assets/uploads';

然后 $filename 像这样

$filename = 'foo.bar';

保存图片的最后一部分

Image::make($image)->resize(300, 300)->save( public_path($path . '/' . $filename ) );

在保存图像之前将其添加

   if (!is_dir($path)) {
        \File::makeDirectory($path, $mode = 0755, true, true);
    }

但如果您需要最佳解决方案,则需要使用

\Storage::disk('public')->put(your_path,$image);