HTML5 调用手机相册和摄像头的方法并上传微信下测试通过

<input type="file" capture="camera" accept="image/*" id="cameraInput" name="cameraInput">

 

复制代码
$("#cameraInput").on('change',function(){

var file = this.files[0]
//alert(img);
var reader = new FileReader();
reader.readAsDataURL(file);

reader.onload = function(evt) {
$("#imgprv").attr("src",this.result);
$("#imgprv").attr("data-b64",encodeURIComponent(this.result));

}

});
复制代码

PHP接收端

复制代码
function SetHeader(){
        $uid= $_SESSION['uid'];
        $b64f = urldecode(I("b64f"));
        
        $f       = explode(',', $b64f);
        
        if ( preg_match('/\s*data:image\/(\w+);/',$b64f , $result ) ){
                    file_put_contents( "1.txt", $result[1] );
                    $fName = time().".".$result[1];
                    $file =  C('PICTURE_UPLOAD.rootPath')."newf"."/".$fName;
                    file_put_contents($file, base64_decode( $f[1] ) );
                    //写入数据库
                    M("member")->where("uid=$uid")->save(array("avatar"=>$file));
            
                    
        }
        exit( json_encode(array('status'=>1,'msg'=>'上传成功','data'=>$file) ) );
        
    }
复制代码

 

posted @   方东信  阅读(2636)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示