base64多图片上传如何和后台进行交互( 四 )


    oSubmit.onclick=function(){  
         if(!dataArr.length){   
【base64多图片上传如何和后台进行交互】            return alert('请先选择文件');   
        }   
        s();   
    }   
}              

base64多图片上传如何和后台进行交互



4function ReSizePic(ThisPic) {   
    var RePicWidth = 200; //这里点窜为您想显示的宽度值
          var TrueWidth = ThisPic.width; //图片现实宽度   
    var TrueHeight = ThisPic.height; //图片现实高度 
        if(TrueWidth>TrueHeight){   
        var reWidth = RePicWidth;//广大于高 
        ThisPic.width = reWidth;    
        var nowHeight = TrueHeight * (reWidth/TrueWidth); //垂直居中   
         return nowHeight;  //将图片点窜后的高度返回, 供垂直居顶用   
    }else{  
         var reHeight = RePicWidth; //宽小于高    
         ThisPic.height = reHeight; 
      }   
}   

base64多图片上传如何和后台进行交互



5后台数据处置:
public function upload(){
        foreach ($_POST['image'] as $key => $value) {
            $up_dir = './upload/';//存放在当前目次的upload文件夹下
            if (!file_exists($up_dir)) {
                mkdir($up_dir,0777);
            }
            if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $value,$result)) {
                $type = $result[2];
                if (in_array($type,array('pjpeg','jpeg','jpg','gif','bmp','png'))) {
                    $new_file = $up_dir.date('YmdHis_').rand(10000,99999).'.'.$type;
                    if (file_put_contents($new_file, base64_decode(str_replace($result[1],'',$value)))) {
                        $img_path = str_replace('../../..', '', $new_file);
                        $re[] += 1;
                    }else{

猜你喜欢