[英]Laravel can't upload file in storage folder
I used to store my upload files (images) in my public folder but this time I want to store them in my storage folder and I get this error 我曾经将上传文件(图像)存储在公用文件夹中,但是这次我想将其存储在存储文件夹中,但出现此错误
Can't write image data to path (C:\laragon\www\mynewsite\storage\images/aboutimage-1522481830.png)
Error comes from this line (where I use intervention/image package) 错误来自此行(我在其中使用干预/图像包)
Image::make($image)->resize(1200, 600)->save($location);
My function: 我的功能:
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);
}
any idea? 任何想法?
My files will upload in root/storage
folder instead of root/storage/app/public/images
我的文件将上传到
root/storage
文件夹中,而不是root/storage/app/public/images
why is that? 这是为什么?
I changed my function to code below and it's uploading where it suppose to upload but it does not delete the old image
我将函数更改为下面的代码,并且在需要上传的位置进行上传,但
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);
}
here is final code: 这是最终代码:
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;
}
Basically I gave Root/Storage
path to store data and Public/Storage
path for deleting them in update method. 基本上,我给了
Root/Storage
路径来存储数据,并给了Public/Storage
路径以在更新方法中删除它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.