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 以上就被废弃了, 如果要用就要重新开启

php 将图片文件转成base64编码的方法的更多相关文章

  1. 图片文件转换成Base64编码实现ajax提交图片

    //上传头像图片 function uploadHead(imgPath) { console.log("imgPath = " + imgPath); var image = n ...

  2. js 将图片文件转换成base64

      1.情景展示 在JavaScript中,如何使用图片文件转换成base64? 2.解决方案 /** * 网络图像文件转Base64 * @param img dom对象 */ function g ...

  3. js如何将选中图片文件转换成Base64字符串?

    如何将input type="file"选中的文件转换成Base64的字符串呢? 1.首先了解一下为什么要把图片文件转换成Base64的字符串 在常规的web开发过程中,大部分上传 ...

  4. 将input type="file" 类型的图片文件转成base64

    带有图片的form表单上传数据是很麻烦的,因为图片通常都是和文字分开上传,这是很麻烦的,所有吧图片转成base64就可以和当成文字上传了.话不多少,看代码: 首先定义一个类型为file的input标签 ...

  5. 将图片文件转成BASE64格式

    html5Reader (file, item) { const reader = new FileReader() reader.onload = (e) => { this.$set(ite ...

  6. Java对网络图片/本地图片转换成Base64编码和解码

    一.将本地图片转换成Base64编码字符串 /** * 将本地图片转换成Base64编码字符串 * * @param imgFile 图片目录路径 * @return */ public static ...

  7. delphi将图片转换成Base64编码函数

    {************************************************************************** 名称: BaseImage 参数: fn: TF ...

  8. php和js中,utf-8编码转成base64编码

    1.php下转化base64编码 php中,文本文件的编码决定了程序变量的编码,比如以下代码在不同编码的php文件中,展示的效果也是不一样的 <?php $word = '严'; echo ba ...

  9. Linux中将一个GBK编码的文件转换成UTF-8编码文件

    Linux中将一个GBK编码的文件转换成UTF-8编码文件 使用iconv 命令iconv -f GBK -t UTF-8 file1 -o file2 输出另一个文件,然后再覆盖源文件内容

随机推荐

  1. 重载new和delete运算符

    内存管理运算符 new.new[].delete 和 delete[] 也可以进行重载,其重载形式既可以是类的成员函数,也可以是全局函数.一般情况下,内建的内存管理运算符就够用了,只有在需要自己管理内 ...

  2. 【csp模拟赛九】--dfs

    思路: 这道题可以宽搜,深搜,最短路 代码: #include<cstdio> #include<cstring> #include<iostream> #incl ...

  3. P3478 [POI2008]STA-Station

    题目描述 The first stage of train system reform (that has been described in the problem Railways of the ...

  4. git submodule subtree常用指令

    submodule 官方文档 添加 git submodule add -b master git@git.xxx:xxx/xxx.git src/xxx 删除 git submodule deini ...

  5. 修改input输入框的样式

    直接上代码 <style> .input{ -web-kit-appearance:none; -moz-appearance: none; font-size:1.4em; height ...

  6. ShardingSphere Hint模式 SpringBoot + Mybatis

    ShardingSphere Hint模式不需要对sql进行解析,就可以进行数据库或者表的路由.下面贴一下代码,关于SpringBoot + Mybatis + ShardingSphere怎样结合. ...

  7. avalon里面倒计时功能2

    // 转格式 timeStamp: function (second_time) { var time = parseInt(second_time) + "秒"; ) { ; ) ...

  8. oracle之case

    使用oracle时,不免会用到判断后转换为要展示的值,这里常用case,如下: SELECT (case ) then 'yes' ) then 'no' else 'other' end) --no ...

  9. Co-Clustering_Reproducing

    调包一时爽,复现马上躺. Co-Clustering 注意右上角的:"Edit on GitHub",一开始疯狂吐槽没有源码,复现得非常难受,今天刚做完GM05中Algotirhm ...

  10. python pip settools 安装基于源码 gdal安装需要c++相关库