【问题标题】:How can I upload image using Storage::put on the laravel?如何在 laravel 上使用 Storage::put 上传图片?
【发布时间】:2018-08-11 08:42:37
【问题描述】:

我上传图片的代码如下:

$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

所以我想将名为 chelsea.jpg 的文件保存到 /app/public/product/

【问题讨论】:

    标签: laravel filesystems storage image-uploading laravel-5.6


    【解决方案1】:

    简单的方法

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

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

    这是另一个例子

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

    希望对你有帮助

    【讨论】:

    • 我想用这个:Storage::put($fileName, $file->getRealPath());。但是如何设置路径?我想保存图像:$path = storage_path('/app/public/product/');
    • @SuccessMan laravel 默认为您执行此操作。它将保存在storage/app/public/yourfolder
    • 太棒了。感谢您的帮助
    猜你喜欢
    • 2019-05-30
    • 2014-10-10
    • 2020-07-03
    • 2021-09-29
    • 2020-07-26
    • 1970-01-01
    • 2023-03-04
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多