微信公众号aiax上传多张图片限制两张

微信公众号aiax上传多张图片限制两张_第1张图片

      https://gitee.com/yinfanliang/chengyang.git 

html>
lang="en">

    charset="UTF-8">
    demo</span>页面<span style="color:#e8bf6a;">
    name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
    rel="stylesheet" href="https://cdn.bootcss.com/layer/3.1.0/mobile/need/layer.css">
    rel="stylesheet" href="./css/style.css">
    
    
    
    

style="background-color: #dcdede">
class="container-fluid">
role="form">
class="form-group">
class="z_photo">
class="z_file"> type="file" name="file" id="file" value="" accept="image/*" multiple οnchange="imgChange('z_photo','z_file');"/>
class="z_mask">
class="z_alert">

确定要删除这张图片吗?

class="z_cancel">取消 class="z_sure">确定

( isset ( $_GET [ 'id' ])) { ?> type= "hidden" value= " $_GET [ 'id' ] ?> " name= "open_id" id= "open_id" > } ?> type= "hidden" value= "" name= "pic" id= "pic" >
 
 public static function saveUploadImg()
    {
        if(isset($_GET['isAndroid'])){
            $output_directory = './upload'; //设置图片存放路径
            /* 检查并创建图片存放目录 */
            if (!file_exists($output_directory)) {
                mkdir($output_directory, 0777);
            }
            $upload=new UploadFile();
            $upload->maxSize  = 3*pow(2,20) ;// 设置附件上传大小  3M    默认为2M
            $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型   默认为空不检测扩展
            $upload->savePath =  $output_directory;// 设置附件上传目录   默认上传目录为 ./uploads/

            if(!$upload->upload()) {
                // 上传错误提示错误信息
                echo json_encode(['code' => -1,'msg'=>$upload->getErrorMsg()]);
            }else{
                // 上传成功 获取上传文件信息
                $info =  $upload->getUploadFileInfo();
                echo json_encode(['path' => '/weixin/upload/' . $info[0]['savename'], 'code' => 1]);
            }
        }else{
        if (!isset($_POST['base64img'])) return false;
        $base64_image_content = $_POST['base64img'];
        $output_directory = './upload'; //设置图片存放路径

        /* 检查并创建图片存放目录 */
        if (!file_exists($output_directory)) {
            mkdir($output_directory, 0777);
        }
        /* 根据base64编码获取图片类型 */
        if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) {
            $image_type = $result[2]; //data:image/jpeg;base64,
            $output_file = $output_directory . '/' . md5(time()) . '.' . $image_type;
        }
        /* 将base64编码转换为图片编码写入文件 */
        $image_binary = base64_decode(str_replace($result[1], '', $base64_image_content));
        if (file_put_contents($output_file, $image_binary)) {
//            echo $output_file; //写入成功输出图片路径
            echo json_encode(['path' => '/weixin' . trim($output_file, '.'), 'code' => 1]);
        } else {
            echo json_encode(['code' => -1]);
        }
        }


    }


你可能感兴趣的:(js)