如何使用Storage :: put on laravel上传图像?

问题描述 投票:0回答:1

我上传图片的代码如下:

$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的文件

laravel filesystems storage image-uploading laravel-5.6
1个回答
2
投票

简单的方法

$path = $request->file('avatar')->storeAs(
'avatars', $request->user()->id
);

这将自动将文件存储在默认配置中。

这是另一个例子

Storage::put($fileName, $path);

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.