首页 > 解决方案 > PHP/Laravel:存储::磁盘()。提供真实,但不应该

问题描述

Laravel 5.2 我不明白。我正在检查文件夹中是否存在文件。没有文件,但我得到true.

我尝试了不同的方法,例如:

Storage::disk('local')->exists($path_to_json . array_first($text['other'])); //true

Storage::disk('local')->has($path_to_json . array_first($text['other'])); //true

if(file_exists($path_to_json . array_first($text['other']))) //always false, even if file is there

dd($path_to_json) // "list/text-1a/" 

filesystems.php看起来不错,我可以将文件上传到我需要的地方。

'default' => ('local'),
'disks' => [

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

有人有同样的问题吗?我读过一些主题,有相反情况的人,当文件在文件夹中时他们会得到错误。

更新。Storage::disk如果我可以这么说,“错误”是合乎逻辑的。或者在我的脑海里。 $text['other']has preg_grep,它检查文件扩展名。排除txt和png。 Storage::disk看到,有 txt 文件和 retuns TRUE。但我正在检查其他没有 txt 或 png 的文件。这就是为什么必须稍微重构验证的原因:

 Storage::disk('local')->exists($path_to_json . $id . '_datafile.json');

在这里,我们正在寻找扩展名为 JSON 的特定文件。这就是问题所在。如果我把自己说清楚,我会很高兴。

标签: phplaravelfilestorage

解决方案


推荐阅读