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}
ThinkPHP V5.0 图片上传base64

薛定谔的盒子猫
2021-08-23
2008 0 0
点赞
收藏
评论区
加载中...