Zabs Zabs - 6 months ago 245
PHP Question

File not found at path in laravel 5.2

I have an image within the public/badges directory called 1.png - I am trying to use the Storage library in laravel but keep getting the following error even though the file does exist at that location:

// Error

FileNotFoundException in Filesystem.php line 381:
File not found at path: Users/gk/Sites/mysite/public/badges/1.png


// Code

$filePath = 'badges/1.png';
$path = public_path()."/".$filePath
Storage::disk('local')->get($path);
dd($contents);

Answer

Form Laravel 5.2 documentation:

When using the local driver, note that all file operations are relative to the root directory defined in your configuration file. By default, this value is set to the storage/app directory.

So You are looking for file in: storage/app/Users/gk/Sites/mysite/public/badges/1.png

Error is quite confusing.

[Update]

Add to config/filesystems.php

'disks' => [

    //... 

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

    //... 
],

then

$filePath = 'badges/1.png';
$content = Storage::disk('local_public')->get($filePath);
dd($content);
Comments