【发布时间】:2018-09-10 03:31:24
【问题描述】:
我以前将上传文件(图像)存储在我的公用文件夹中,但这次我想将它们存储在我的存储文件夹中,但出现此错误
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
这是为什么呢?
更新 2
我将我的函数更改为下面的代码,它正在上传它应该上传的位置,但 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);
}
【问题讨论】:
-
试试这个
$location = storage_path('/images/' . $filename); -
@Nawin 仍在存储文件夹中上传:/
-
你的存储路径是什么返回并打印你的
$location变量 -
我如何获得打印的内容?
-
给我
C:\laragon\www\mynewsite\storage\imagesaboutimage-1522483434.png"
标签: php laravel laravel-storage