ThinkPHP V5.0 图片上传base64

1/** 2 * 单图上传 3 * @return bool|mixed|string 4 */ 5protected function uploading_qrcode($images = '',$name ='') 6{ 7 if(empty($images)) $this->result($images, 0, '图片错误'); 8 if (preg_match('/^(data:\s*image\/(\w+);base64,)/',$images,$result)){ 9 $type = $result[2];//图片后缀 10 $new_file =Env::get('root_path') . 'public' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'images';//文件路径 11 $url = DIRECTORY_SEPARATOR . date("Ymd", time()) . DIRECTORY_SEPARATOR;//文件路径 12 $new_file=$new_file.$url;//文件路径 13 if (!file_exists($new_file)) { 14 //检查是否有该文件夹,如果没有就创建,并给予最高权限 15 mkdir($new_file, 0777,true); 16 } 17 18 $filename = $name. ".{$type}"; //文件名 19 $new_file = $new_file . $filename;//全部路径 20 $url = $url.$filename;//存储路径 21 //写入操作 22 if(file_put_contents($new_file, base64_decode(str_replace($result[1], '', $images)))) { 23 $url = 'uploads' . DIRECTORY_SEPARATOR . 'images' . $url;; 24 return $url; 25 } 26 } 27}
点赞
收藏

评论区

加载中...

相关推荐

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

Opencv学习笔记2:图像模糊作用和方法

一、意义和作用:图像的模糊处理就是将图片处理的更加模糊,如下图,左侧是原图,右侧是经过处理之后的图片。!(https://images2018.cnblogs.com/blog/1159866/201807/1159866201807261119591961700830839.png)从主观意愿上说,我们希望看到清晰的图

PhoneGap设置Icon

参考:http://cordova.apache.org/docs/en/latest/config\_ref/images.html通过config.xml中的<icon标签来设置Icon<iconsrc"res/ios/icon.png"platform"ios"width"57"height"57"densi

MSTP+VRRP+OSPF+双出口

拓扑图!MSTPVRRPOSPF双出口(https://s4.51cto.com/images/blog/202012/14/3e101c381bc712f9915994275649ac00.png?xossprocessimage/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFF

GridView实现九宫格

GridViewgv(GridView)findViewById(R.id.g1);    ArrayList<HashMap<String,ObjectdatanewArrayList<HashMap<String,Object();    for(inti0;i<images.length;i)