zoukankan      html  css  js  c++  java
  • 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) ) );
            
        }
  • 相关阅读:
    无线传感网3-1.目标物的覆盖技术
    无线传感网2-传感器布局方法
    JAVA 第二周课程总结
    2019春总结作业
    第十二周作业
    第十一周作业
    第十周
    第九周作业
    第八周作业
    第七周作业
  • 原文地址:https://www.cnblogs.com/cfas/p/5443183.html
Copyright © 2011-2022 走看看