doudi5291 2018-09-25 18:09
浏览 1913
已采纳

在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

  • 写回答

1条回答 默认 最新

  • dtdfl62844 2018-09-25 18:18
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?