Zabs
Zabs

Reputation: 14142

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);

Upvotes: 5

Views: 33232

Answers (2)

Miharbi Hernandez
Miharbi Hernandez

Reputation: 429

I had the same problem in Laravel 5.7, this fix my problem:

php artisan storage:link

Upvotes: -1

Pyton
Pyton

Reputation: 1319

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);

Upvotes: 11

Related Questions