html5上传图片php特殊处理一下

$file=$_POST['file'];
        if($file)
        {
            preg_match('|data:image/([a-zA-Z]+);base64,|s',$file,$match);
            $file_name=md5($uid).'.'.$match[1];
            $fp=fopen(__ROOTDIR__.'/upload/avatar/'.$file_name,'w+');
            //去除base64不能解码的部分
            $file=str_replace('data:image/'.$match.';base64,','', $file);
            $file=str_replace(' ','+',$file);
            //解码存放
            $file=base64_decode($file);
            fwrite($fp,$file);
            fclose($fp);
            $data['status']=1;
            $data['data']='http://www.meiyoule.com/upload/avatar/'.$file_name;
        }
原文地址:https://www.cnblogs.com/sixiong/p/4921683.html