【问题标题】:Laravel Storage facade not returning good pathLaravel Storage 门面没有返回好的路径
【发布时间】:2017-05-29 11:02:39
【问题描述】:

我正在尝试将一些文件上传到 Laravel 中的特定“磁盘”,然后从这些文件中检索 URL。

这是我的config/filesystem.php 文件:

'disks' => [
    ...
    'thumbnails' => [
        'driver' => 'local',
        'root' => storage_path('app/public/pictures/thumbnails'),
        'visibility' => 'public',
    ],
    ...
],

这是我处理上传文件的方式(非常基本,仅用于测试目的):

Route::post('upload', function(Request $request) {
    $file = $request->file('file');
    $path = $file->storeAs('/', 'myFile.'.$file->getClientOriginalExtension(), 'thumbnails');
    return dd($path);
});

文件/storage/app/public/pictures/thumbnails/myFile.jpg 已创建,这很好,但$path 等于"myFile.jpg" 而不是完整路径。第一件奇怪的事。

如果我使用:

$url = Storage::disk('thumbnails')->url('myFile.jpg');

$url 等于 "/storage/myFile.jpg" 而不是 "/storage/app/public/pictures/thumbnails/myFile.jpg"

我错过了什么吗?

【问题讨论】:

    标签: php laravel laravel-5.3


    【解决方案1】:

    默认情况下,磁盘url 方法只是在/storage 前面加上docs 中所述。

    要自定义 url,请将 url 添加到您的配置中:

    'thumbnails' => [
        'driver' => 'local',
        'root' => storage_path('app/public/pictures/thumbnails'),
        'visibility' => 'public',
        'url' => 'the url',
    ],
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2017-10-21
      • 2014-12-07
      • 2018-06-15
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多