如何在 laravel 上使用 Storage::put 上传图片?
How can I upload image using Storage::put on the laravel?
我上传图片的代码是这样的:
$file = $file->move($path, $fileName);
代码有效
但我想使用 Storage::put 来更改它,就像这个参考:
https://laravel.com/docs/5.6/filesystem#storing-files
我这样试:
Storage::put($fileName, $path);
没用
我很困惑,我必须把 $file
放在代码上的地方
我该如何解决这个问题?
更新 :
$file = file of image
$path = storage_path('/app/public/product/')
$fileName = chelsea.jpg
所以我想在 /app/public/product/
上保存名称为 chelsea.jpg 的文件
简单方法
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);
这会自动将文件存储在您的默认配置中。
这是另一个例子
Storage::put($fileName, $path);
希望对您有所帮助
我上传图片的代码是这样的:
$file = $file->move($path, $fileName);
代码有效
但我想使用 Storage::put 来更改它,就像这个参考:
https://laravel.com/docs/5.6/filesystem#storing-files
我这样试:
Storage::put($fileName, $path);
没用
我很困惑,我必须把 $file
放在代码上的地方
我该如何解决这个问题?
更新 :
$file = file of image
$path = storage_path('/app/public/product/')
$fileName = chelsea.jpg
所以我想在 /app/public/product/
简单方法
$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);
这会自动将文件存储在您的默认配置中。
这是另一个例子
Storage::put($fileName, $path);
希望对您有所帮助