//说明:浏览该文件将看到N多行字符串
$file= ‘upall.gif’;
$fp = fopen($file, ‘rb’, 0);
echo chunk_split(base64_encode(fread($fp,filesize($file))));
fclose($fp);
//如何使用PHP对图片进行base64解码输出
$image = <<< EOFILE
R0lGODl(upall注:这里省略部分BASE64字符串)CAgAOw==
EOFILE;
header(“Content-type: image/gif”);
exit(base64_decode($image));
//HTML中的用法:
<img src=”data:image/gif;base64,R0lGODl(这里省略部分BASE64字符串)CAgAOw==”/>
//CSS中这样写:
<p style=”background:url(‘data:image/gif;base64,R0lGODl(再省略部分字符)CAgAOw==’)”>
base64背景图片
</p>