Laravel File not found at path but it does exist

30,383

Solution 1

I figured it out.

Storage::get actually uses the path relative to the filesystem disk configuration, therefore the error message itself is misleading.

I've corrected the issue by simply using file_get_contents() instead.

Solution 2

As others pointed out Storage::get indeed uses the path relative to the filesystem disk configuration, by default the local driver is used (config/filesystems.php):

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

So if you are using the local driver and your file resides at app/public/yourfile.ext for example then the call to Storage should be:

Storage::get('public/yourfile.ext');
Share:
30,383
kjdion84
Author by

kjdion84

Updated on November 03, 2020

Comments

  • kjdion84
    kjdion84 over 3 years

    Getting the following error in console when attempting to get a files contents:

    [League\Flysystem\FileNotFoundException] File not found at path: C:/wamp64/www/lion/resources/generate/json/Car.json

    When I copy and paste that exact path in explorer it opens the json file fine.

    Here is my code:

    $this->json = json_encode(Storage::get(resource_path('generate/json/'.$this->argument('model').'.json')));
    
  • Leonardo
    Leonardo about 4 years
    Thank you. I was missing "public/myFolder/myFile.txt".
  • saber tabatabaee yazdi
    saber tabatabaee yazdi almost 4 years
    i have this issue for delete. when i get from client and save is ok and save filename in db but when i want to delete $this->logo is relative url path i dont know why?