简体   繁体   中英

Convert Image to Base64 PHP

I am 100% sure that I have a file on that path.

在此处输入图片说明

I'm trying to convert my logo.png to base64

$imagedata = file_get_contents("/images/account/operator/logo.png");
$base64 = base64_encode($imagedata);

I kept getting

file_get_contents(/images/account/operator/logo.png): failed to open stream: No such file or directory

You're using the absolute path. Unless there's an /images dir in your root folder on the server, file_get_contents() won't be able to access it. Modify your path to the image to use the correct value.

您必须使用绝对路径:

$_SERVER['DOCUMENT_ROOT']. '/images/account/operator/logo.png'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM