在laravel php中将现有图像转换为base64

I'm trying to show the user saved images in product edit page. I'll show the images which is uploaded by the user in add product. I'm trying to convert the image to base64 format to show it in background.

when I use

file_get_contents

in my Controller it's gives me this error.

file_get_contents(full_path_to_image): failed to open stream: No such file or directory

My images is stored under "public/images/upload/FILE_NAME"

is there any trick that I miss or something that I make wrong

If your upload images in public folder try:

$path = public_path('images/upload/file_name');

If your upload images in Storage public folder try:

$path = storage_path('images/upload/file_name');

To encode the image to base64 try:

base64_encode($file_path);