1
votes

I have a Laravel 5.6 project running on a Windows Bitnami WAMP stack. I am storing an image like this..

$imageName = myfile.jpg
$path = $request->file->storeAs('images', $imageName);

This works and the file is correctly stored, I am trying to retrieve it like this..

$source = Storage::get('images', $imageName);

But I get the error message...

file_get_contents(C:\Bitnami\wampstack-7.1.18-1\apache2\htdocs\myproject\storage\app\images): failed to open stream: Permission denied

This looks like a permissions issue, the storage\app\images folder looks like this

drwxr-xr-x 1 win_user 192142 0 Jul  2 18:15 images

Anyone any ideas where I am going wrong?

2
Make sure the whole storage folder has the correct permissions - Vilius
Have confirmed 0755 permissions on storage folder and all subfolders - fightstarr20
755 is supposed to be for folders and 644 for files - Vilius
Correct, both are set correctly - fightstarr20
Who owns the file (image) that gets stored? - J. Arbet

2 Answers

1
votes

file_get_contents(C:\Bitnami\wampstack-7.1.18-1\apache2\htdocs\myproject\storage\app\images): failed to open stream: Permission denied

you are save the file to default local disk, check your config/filesystems.php

default local disk is not allow access by url

'disks' => [

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

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],

oops, my mistake, you are get the file, not display the image by url

try $source = Storage::get('images/' . $imageName);

0
votes

It's permission issue. Execute the following commands in the parent directory of your document root.

Please note that public_html is not a public directory of the laravel project. It's the parent directory.

For Ubuntu:

sudo chown -R www-data:www-data public_html

For centOS

sudo chown -R apache:apache public_html

In case your web server does not have permissions to write a file, executing these commands will solve the issue. Let me know if it helps.