0

In laravel, I am making an application that uploads a file and the user can retrieve that same file.

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

I tried php artisan storage:link

Can anyone suggest any solution, please?

  • 2
    have you ran this command `php artisan storage:link`? – Salman Zafar Jul 24 '19 at 11:48
  • May be because of cache ? – Sagar Gautam Jul 24 '19 at 11:48
  • by default `storage::disk('public')` will prepend the path with `/your/path/to/project/storage/app/public/` – Clément Baconnier Jul 24 '19 at 11:49
  • Yeah I tried `php artisan storage:link`. – suganthan sivananthan Jul 24 '19 at 11:50
  • 2
    Maybe it's just a typo cause you have `/storage/ap/` but the default would be `/storage/app/`. – jelhan Jul 24 '19 at 11:52
  • Your file is located under the `/your-app/public/storage` folder, not `/your-app/storage/app/public/storage` folder. Is that that right? – Clément Baconnier Jul 24 '19 at 11:57
  • 1
    If you didn't change the default storage disk then it's not going to upload it to that specific disk by default. So you could try to just use Storage::get($filePath); This is all specified in config/filesystems.php Storage::disk('public') is not a method to select the public folder. It's a method to select the 'public' disk. The path is a bit different So if you didn't specify that your app uses public by default it will probably be on the 'local' disk. EDIT: @cbaconnier his answer details on how to add a disk with your specific file path. – Kerel Jul 24 '19 at 12:07

2 Answers2

1

Since your file is located at this place /your-app/public/storage/ap/payments/filename.pdf you need to add a disk.

In the file 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. 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')

Even better, since it's a a 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. But that's maybe more advanced stuff.

Clément Baconnier
  • 5,718
  • 5
  • 29
  • 55
  • I have tried this. I added the disk and tried this code. still, doesn't work. Now I get an error that `InvalidArgumentException in FilesystemManager.php line 121: Driver [] is not supported.`. – suganthan sivananthan Jul 25 '19 at 04:05
  • @suganthansivananthan your file do looks like this: https://pastebin.com/DPijxM2G right? Then, maybe try `php artisan config:clear` – Clément Baconnier Jul 25 '19 at 06:42
-1

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);
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57