简体   繁体   中英

Convert Base64 to original image path

I'm using the following code to encode my image path. I want to know if it is safe or someone can decode the original file path from encoded string?

$imagedata = file_get_contents("ab/test.png");
$base64 = base64_encode($imagedata);
echo '<img src="data:image/jpeg;base64,'.$base64.'" />';

also do i have to use data:image/jpeg or png or gif or any extension would work?

They can decode the data, but can't know what the original filename was. The encoded data contains just the image data, not its meta -data (as in filename, mime-type -not directly-, inode, etc).

As per your second question: you must use the proper MIME type that matches the data, otherwise the browser/client won't understand its contents.

您正在将文件内容加载到Base64编码的字符串中,所以不,它们无法获取路径,因为您仅提供了内容。

If by "safe" you mean reversible then no, it is not safe.

Base64 encodes data which can be decoded easily with base64_decode. Someone would be able to decode your base64 data into the original image.

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