我曾经将我的上传文件(图片)存储在我的公共文件夹中,但这次我想将它们存储在我的存储文件夹中,我收到此错误
Can't write image data to path (C:\laragon\www\mynewsite\storage\images/aboutimage-1522481830.png)
错误来自此行(我使用intervention/image包)
Image::make($image)->resize(1200, 600)->save($location);
我的功能:
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'aboutimage' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('images/' . $filename);
Image::make($image)->resize(1200, 600)->save($location);
$oldFilename = $indexabout->image;
$indexabout->image = $filename;
Storage::delete($oldFilename);
}
任何想法?
我的文件将上传到root/storage
文件夹,而不是root/storage/app/public/images
为什么会这样?
我将我的功能更改为下面的代码,并将其上传到上传的位置,但it does not delete the old image
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = '/aboutimage' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('app/public/images' . $filename);
Image::make($image)->resize(1200, 600)->save($location);
$oldFilename = $indexabout->image;
$indexabout->image = $filename;
Storage::delete($oldFilename);
}
答案 0 :(得分:1)
这是最终代码:
if ($request->hasFile('image')) {
$image = $request->file('image');
$filename = 'aboutimage' . '-' . time() . '.' . $image->getClientOriginalExtension();
$location = storage_path('app/public/images/' . $filename); // root storage path
Image::make($image)->resize(1200, 600)->save($location);
Storage::delete('images/' . $indexabout->image); //public storage path
$indexabout->image = $filename;
}
基本上我提供了Root/Storage
路径来存储数据,Public/Storage
路径用于在更新方法中删除它们。