[英]Can’t send a file response for the storage folder in Laravel 5.2 on Homestead
[英]Laravel can't upload file in storage folder
我曾经将上传文件(图像)存储在公用文件夹中,但是这次我想将其存储在存储文件夹中,但出现此错误
Can't write image data to path (C:\laragon\www\mynewsite\storage\images/aboutimage-1522481830.png)
错误来自此行(我在其中使用干预/图像包)
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);
}
这是最终代码:
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
路径以在更新方法中删除它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.