1

我在 storage/public 有一个图像,我想使用 Storage library 访问它,但我收到错误“在路径中找不到文件”

我在互联网上搜索了很多,但我的问题没有得到任何解决方案,所以请帮助我。

我的代码:

$filename = '123.jpg';
$path = storage_path()."/".$filename;
Storage::disk('local')->get($path);
dd($contents);

错误 :

Illuminate\Contracts\Filesystem\FileNotFoundException
C:\xampp\htdocs\admin\storage/123.jpg

我试过的东西:

php artisan storage:link

文件系统.php

<?php

return [
    'default' => env('FILESYSTEM_DRIVER', 'local'),

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
            'permissions' => [
                'file' => [
                    'public' => 0664,
                    'private' => 0600,
                ],
                'dir' => [
                    'public' => 0775,
                    'private' => 0700,
                ],
            ]
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL') . '/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

    'links' => [
        public_path('storage') => storage_path('app/public'),
    ],

];

4

1 回答 1

1

您的文件在storage/public文件夹下,但您尝试从storage文件夹访问它。

检查您的错误路径C:\xampp\htdocs\admin\storage/123.jpg

改变

$path = storage_path()."/".$filename;

$path = storage_path('public/' . $filename);
于 2020-03-24T13:09:16.553 回答