omrcm
omrcm

Reputation: 31

Convert existed images to base64 in laravel php

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

Upvotes: 0

Views: 8659

Answers (1)

Gihan Lakshan
Gihan Lakshan

Reputation: 403

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

Upvotes: 1

Related Questions