php 将图片文件转成base64编码的方法


php 将图片文件转成base64编码的方法
<pre>
<?php

/** 文件转base64输出
* @param String $file 文件路径
* @return String base64 string
*/

function fileToBase64($file){
$base64_file = '';
if(file_exists($file)){
$mime_type= mime_content_type($file);
$base64_data = base64_encode(file_get_contents($file));
$base64_file = 'data:'.$mime_type.';base64,'.$base64_data;
}
return $base64_file;
}

print_r(fileToBase64('bd_logo1.png'));
exit();
?>
</pre>
base64编码直接 在浏览器地址栏输入就可以看到图片啦。。
ps:mime_content_type函数在 php5.3 以上就被废弃了, 如果要用就要重新开启


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM