Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Prabodhana's avatar

Laravel Storage::get() not working

I want to get image file in laravel storage folder and encode it to base64. If I use this code it always return empty value

$data = base64_encode(Storage::disk('public')->get('/customer/Avatars',"image.png"));

In localhost this code works

$data = base64_encode(file_get_contents(public_path().'/storage/customer/Avatars/'."image.png"));

but after upload to cpanel this above code give me this error

ErrorException: file_get_contents(/home/site/wwwroot/public/storage/customer/Avatars/image.png): failed to open stream: No such file or directory in file /home/site/wwwroot/app/Http/Controllers/Customer/CustomerProfileController.php on line 56

How can I get this file?

0 likes
6 replies
tisuchi's avatar

@prabodhana Since it works locally, make sure your directory name is Avatars not avatars.

If the avatars directory is lowercase, update your code here-

$data = base64_encode(file_get_contents(public_path().'/storage/customer/avatars/'."image.png"));
tisuchi's avatar

@prabodhana I mean whether it's lowercase (avatars) or the First letter is uppercase Avatars?

tisuchi's avatar

@prabodhana it should be lowercase avatars because in the server Uppercase and lowercase are not the same. That's why you are getting errors, probably.

Prabodhana's avatar

Im tried changing folder name to lowercase but still getting same error

Please or to participate in this conversation.