我正在使用 laravel 5.2,在处理图像上传时遇到问题。我收到错误为
NotWritableException in Image.php line 143: Can't write image data to path (C:\Users\SurajLifeean\surj\public\images/)
此代码位于我的 Controller 内。
$image=$request->file('featured_image');
$filename=time().'.'.$image->getClientOriginalExtension();
$location = public_path('images/',$filename);
Image::make($image)->resize(800,400)->save($location);$post->image=$filename;
我已经找到了一个要在开头包含的解决方案
use Illuminate\Support\Facades\File;
但这并没有帮助。 谁能给我建议一个解决方案
最佳答案
根据您的错误消息,您遇到了两个问题,
1 ) NotWritableException
表示您尝试访问的文件夹不可写,这意味着您需要授予该文件夹 777 权限
2)你是在windows环境下,而你使用的是UNIX目录分隔符。
使用DIRECTORY_SEPARATOR
常量作为目录分隔符而不是固定分隔符始终是一个好习惯。
如下:
$location = public_path('images' . DIRECTORY_SEPARATOR, $filename);
或者只是在您的情况下使用:
$location = public_path('images\', $filename);
关于php - Image.php 第 143 行中的 NotWritableException : Can't write image data to path (C:\Users\SurajLifeean\surj\public\images/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43292445/