您的位置:首页 > 其它

后台处理base_64图片的方法

2017-06-12 11:38 281 查看
这里以YII2 框架为例

$v  是前台传过来的base_64的信息

if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $v, $result)){

                   $type = $result[2];

                   $imgDir = './uploadss/';

                   $filename =rand().time()."_".$uid.$type; //新图片名称

                   $newFilePath = $imgDir.$filename;

                   if (file_put_contents($newFilePath, base64_decode(str_replace($result[1], '', $v)))){

                      $res[]=yii::$app->request->hostInfo."/uploadss/" . $filename;

                  }

      }

经过处理之后

$res[]=yii::$app->request->hostInfo."/uploadss/" . $filename;图片的存放地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: