如何解决“在路径中找不到文件”错误?

时间:2020-04-25 11:09:26

标签: php laravel storage laravel-7

我在中等模型中编写了一个函数来获取文件的可见性,而我是通过访问器做到的

我的功能:

public function getVisibilityAttribute()
{
 return Storage::getVisibility(storage_path('app/' . $this->getOriginal('path')));
// the path comes from database and here is 'public/test/user.jpg'
}

从数据库中获取数据以显示文件后,出现此错误:

exception: "League\Flysystem\FileNotFoundException"
file: "C:\xampp\htdocs\admin\vendor\league\flysystem\src\Filesystem.php"
line: 389
message: "File not found at path: C:/xampp/htdocs/admin/storage/app/public/test/user.jpg"

但是该路径处存在user.jpg,我可以通过浏览器访问该图像。

那我该怎么解决这个错误?

1 个答案:

答案 0 :(得分:0)

您可以先检查是否运行

php artisan storage:link

然后可以正常工作:

return Storage::disk('public')->getVisibility('test.txt');

文件位置:

/storage/app/public/test.txt

相应地调整getVisibilityAttribute函数,然后可以尝试使用。