【发布时间】:2012-04-01 00:39:59
【问题描述】:
我想将内联 jpg 图像输出为 base64 编码字符串,但是当我这样做时:
$contents = file_get_contents($filename);
print "<img src=\"data:image/jpg;base64,".$contents."\"/>";
其中$filename 是带有base64 图像的本地文本文件。输出如下:
<img src="data:image/jpg;base64,/9j/4A..... (the rest of the file)...." />
而且显然图像没有被渲染,但是 来自哪里?它不在文本文件中。如果删除,图像可以正常显示。
【问题讨论】:
-
你在 var_dump($contents); 中得到了什么?
标签: php image base64 file-get-contents