折雨的天空

新浪微薄腾讯微薄

最新碎语:最近霉到了住。哎。。。

您的位置:折雨的天空 >php开发> 关于html5上传文件,php处理要注意的

关于html5上传文件,php处理要注意的

先来两个参考网址:


http://kuro.tw/posts/2013/09/08/php-html5-canvas-resulting-base64-datauri-images-will-be-uploaded-to-the-server-side-processing


http://www.oschina.net/question/2261060_213583


实际这两个网址都说的很清楚了,处理图片是用的base64编码的方式


$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;
        }

------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------

转载请注明本文标题和链接:《关于html5上传文件,php处理要注意的

奖励一下

取消

分享不易,烦请有多多打赏,如您也困难,点击右边关闭即可!

扫码支持
扫码打赏,5元,10元,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

-秒后自动关闭,如已打赏,或者不愿打赏,请点击右上角关闭图标。

发表评论

路人甲 表情
看不清楚?点图切换