Laravel的Storage :: File找不到我的文件

时间:2018-11-19 14:43:15

标签: php laravel controller storage

我想计算存储目录中有多少张图像,但是似乎Storage::Files找不到任何图像,我已经在storage\app\public\property\*id_of_the_property*中存储了4张图像,并且已经对{{ 1}},而且链接至少在乍一看就可以正常工作。

这是我的php artisan storage:link

config\FilesSystems.php

还有我的控制者:

'disks' => [

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

        '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'),
        ],

    ],

但是变量public function show($id) { $show = []; $directory = 'property/'.$id; $files = Storage::Files($directory); $count = count($files); $show['count'] = $count; $show['directory'] = $directory; return $show; } 在应为4的情况下显示0,而$show['count']没有做任何事情,因为Storage::Files显示的是“ property / 1”并且1是id我正在测试。我想念什么?

我尝试使用:

$show['directory']

$directory = Storage::url('property/'.$id);
/* Result "/storage/property/1" */
$directory = Storage::url('app/public/property/'.$id);
/* Result "/storage/app/public/property/1" */

但也没有成功,计数仍然为0。

谢谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您可以使用文件外观

use Illuminate\Support\Facades\File;
...
$images = File::allFiles(storage_path('app/public/property')); // this is recursive

$images = File::files(storage_path('app/public/property/'.$id)); // this is NOT recursive

答案 1 :(得分:0)

使用public_path($ directory);为此