skip to Main Content

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?

2

Answers


  1. you can any found file path on storage folder with laravel global storage_path helper

    $imagePath=storage_path('customer/Avatars/image.png');
    
    

    if you get file path in public folder

    $imagePath=public_path('customer/Avatars/image.png');
    
    Login or Signup to reply.
  2. This happened to me and I would like to share it because some of you can be having the same problem, I was trying to use Storage::get() method for encoding a file, but, that returned an empty field, finally I realized that the file that I was getting with the method was empty inside, so make sure your dummy files has some content inside, otherwise it will always return empty.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search