【问题标题】:wrong path displayed for stored files为存储的文件显示错误的路径
【发布时间】:2016-09-29 18:41:15
【问题描述】:

我正在使用 laravel 图像干预。我的 Storage 文件夹中存储了一些文件,位于 /storage/app/public/images 的路径中。当我尝试生成文件的路径时由

$path=Storage::disk('local')->url('screenshot1.jpg');

并做 dd($path),它给了我这样的路径,

"/storage/screenshot1.jpg"

我想要一条路,

"/storage/app/public/images/screenshot1.jpg"

我还在我的 filesystem.php 中进行了一些更改以获得所需的路径,

'disks' => [

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app/public/images'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public/images'),
        'visibility' => 'public',
    ],

    's3' => [
        'driver' => 's3',
        'key' => 'your-key',
        'secret' => 'your-secret',
        'region' => 'your-region',
        'bucket' => 'your-bucket',
    ],

],

但还是不行..

【问题讨论】:

    标签: php laravel-5.2


    【解决方案1】:

    正确返回路径,但是要获取 url 中的内容,您需要将其从存储复制到路径中的 publick 文件夹,否则您应该返回 base64 给客户端。因为存储不能直接从公共访问。

    您需要与 storage/app/public/images 建立符号链接 如果文件夹 images 未公开创建,则在进行符号链接之前创建它

    ln -s storage/app/public/images public/images
    

    【讨论】:

    • 我也将这些图像存储在公用文件夹中,但它仍然返回相同的路径,我是否必须更改此 filesystem.php 文件
    • 为 storage/app/public/images 到 public/images 做符号链接
    • 这是我的 gitbash 返回的,$ ln -s storage/app/public/images public/images ln: failed to create symbolic link 'public/images': No such file or directory
    • 在 public/images 上做 mkdir,这表示 public 文件夹中的文件夹目录 images 不存在,然后做符号
    猜你喜欢
    • 2020-05-20
    • 1970-01-01
    • 2020-05-30
    • 2015-05-15
    • 1970-01-01
    • 2017-01-12
    • 1970-01-01
    • 2021-08-31
    • 2021-02-17
    相关资源
    最近更新 更多