简体   繁体   English

FileNotFoundException即使存在于Laravel中

[英]FileNotFoundException even if it exists in Laravel

In laravel, I am making an application that uploads a file and the user can retrieve that same file. 在laravel中,我正在制作一个上载文件的应用程序,用户可以检索相同的文件。

But each time I click to upload I get this error. 但是每次单击上传时,都会出现此错误。

FileNotFoundException in FilesystemAdapter.php line 91:
/storage/ap/payments/98AcresResort_25.pdf

my controller code is this: 我的控制器代码是这样的:

$filePath = "/storage/ap/payments/".$payment->payment_image;
$file = storage::disk('public')->get($filePath);

my file is located at /public/storage/ap/payments/filename.pdf 我的文件位于/public/storage/ap/payments/filename.pdf

I tried php artisan storage:link 我尝试了php artisan storage:link

Can anyone suggest any solution, please? 有人可以提出任何解决方案吗?

Since your file is located at this place /your-app/public/storage/ap/payments/filename.pdf you need to add a disk. 由于您的文件位于/your-app/public/storage/ap/payments/filename.pdf这个位置, /your-app/public/storage/ap/payments/filename.pdf您需要添加磁盘。

In the file config/filesystems.php 在文件config/filesystems.php

add the disk 添加磁盘

'disks' => [

    'web' => [
        'driver' => 'local',
        'root' => public_path(),
    ],

Then you can use it like this 然后你可以像这样使用它

$filePath = "storage/ap/payments/".$payment->payment_image;
$file = Storage::disk('web')->get($filePath);

It will look for the location 它将寻找位置

/your-app/public/storage/ap/payments/filename.pdf"

But I suspect that your file /public/storage/ap/payments/filename.pdf was also in the /storage folder and that you're working through a symlink. 但是我怀疑您的文件/public/storage/ap/payments/filename.pdf也位于/storage文件夹中,并且您正在通过符号链接进行工作。 The correct ways would be to have app instead of ap and to use the public disk like this Storage::disk('public')->path('payments/filename.pdf') 正确的方法是使用app而不是ap并使用像Storage::disk('public')->path('payments/filename.pdf')这样的public磁盘

Even better, since it's aa payment, you probably don't want the file to be public and accessible to all. 更好的是,由于它是一种付款方式,因此您可能不希望该文件公开且所有人都可以访问。 In that case you can use the disk local and serve the file on request. 在这种情况下,您可以使用local磁盘并根据要求提供文件。 But that's maybe more advanced stuff. 但这也许是更高级的东西。

You should try this: 您应该尝试这样:

Please run below command for create storage folder in public foler: 请运行以下命令在公共文件夹中创建存储文件夹:

php artisan storage:link


$filePath = public_path("storage/ap/payments/".$payment->payment_image);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM