zoukankan      html  css  js  c++  java
  • 小程序上传图片多图上传

    //上传图片 多图
    choosePic: function() {
    var that = this;
    wx.chooseImage({
    count: 9, // 默认9
    sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有 'original',
    sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
    success: function(res) {
    // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
    var tempFilePaths = res.tempFilePaths;
    //上传图片
    var successUp = 0; //成功个数
    var failUp = 0; //失败个数
    var length = res.tempFilePaths.length; //总共个数

    var i = 0; //第几个
    that.uploadDIY(res.tempFilePaths, successUp, failUp, i, length);
    // console.log(that.data.imglist);
    console.log(that.data.upload_picture_list);
    },
    });
    },

    uploadDIY(filePaths, successUp, failUp, i, length) {
    var that = this;
    var uniacid = app.siteInfo.uniacid;
    var upload_picture_list = that.data.upload_picture_list;
    wx.uploadFile({
    url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Upload&m=pinba',
    filePath: filePaths[i],
    name: 'upfile',
    formData: {},
    success: (resp) => {
    console.log(resp.data);

    successUp++;

    upload_picture_list.push(resp.data);
    that.setData({
    upload_picture_list: upload_picture_list
    })
    console.log(upload_picture_list);

    },

    fail: (res) => {
    failUp++;
    },
    complete: () => {
    i++;
    if (i == length) {
    wx.hideLoading();
    console.log('总共' + successUp + '张上传成功,' + failUp + '张上传失败!');
    } else { //递归调用uploadDIY函数
    this.uploadDIY(filePaths, successUp, failUp, i, length);

    }
    },

    });

    },
     
     
     
    发布
    formSubmit: function(e) {
    var that = this;
    var values = e.detail.value;

    //需处理
    if (e.detail.value.text == "") {
    wx.showToast({
    title: '说点什么吧',
    image: "../images/error.png"
    })
    } else {
    var val = e.detail.value;
    var f_neirong = val.f_neirong
    var upload_picture_list = that.data.upload_picture_list;
    var openid = wx.getStorageSync('openid')
    console.log(val)
    app.util.request({
    'url': "entry/wxapp/Fabufenxiang",
    data: {
    openid: openid,
    f_neirong: f_neirong,
    f_slide: upload_picture_list,
    },
    success: function(res) {
    wx.showToast({
    title: "发布成功!",
    })
    wx.redirectTo({
    url: '../sharefaxian/sharefaxian',
    })
    console.log(res);
    }

    })
    }
    },
     
     
     
     
     
    方法:

    //发布分享
    public function doPageFabufenxiang(){
    global $_W,$_GPC;
    $uniacid = $_W['uniacid'];

    // $idarr =htmlspecialchars_decode($wekinfo);
    // $array =json_decode($idarr);
    // $object =json_decode(json_encode($array),true);
    // $arr =serialize(数据库字段);

    $f_slide = htmlspecialchars_decode($_REQUEST['f_slide']);
    // $arr=substr($f_slide,1,strlen($f_slide)-1);
    // echo "<pre>";print_r($arr);echo "</pre>";
    // $array=substr($arr,0,-1);
    // echo "<pre>";print_r($array);echo "</pre>";


    $array =json_decode($f_slide);//转数组
    $object =json_decode(json_encode($array),true);
    // echo "<pre>";print_r($object);echo "</pre>";


    // $obj = implode(",", $object);

    $data = array(
    "uniacid"=>$uniacid,
    "f_neirong"=>$_REQUEST['f_neirong'],
    "f_slide"=>serialize($object),
    "f_time"=>strtotime(date("Y-m-d H:i:s")),
    );
    $openid = $_REQUEST['openid'];
    $users = pdo_fetch("SELECT * FROM ".tablename("pinba_userinfo")." where uniacid=:uniacid and openid=:openid",array(":uniacid"=>$uniacid,":openid"=>$openid));
    $data['f_xid'] = $users['u_id'];
    $res = pdo_insert("pinba_fenxiang",$data);
    }
    public function doPageUrl()
    {
    global $_W;
    echo $_W['siteroot'];
    }
    public function doPageUpload()
    {
    global $_W, $_GPC;
    $uniacid = $_W['uniacid'];
    $uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png');
    $max_file_size = 2000000;
    $destination_folder = '../attachment/';
    if (!is_uploaded_file($_FILES['upfile']['tmp_name'])) {
    echo '图片不存在!';
    die;
    }
    $file = $_FILES['upfile'];
    if ($max_file_size < $file['size']) {
    echo '文件太大!';
    die;
    }
    if (!in_array($file['type'], $uptypes)) {
    echo '文件类型不符!' . $file['type'];
    die;
    }
    $filename = $file['tmp_name'];
    $image_size = getimagesize($filename);
    $pinfo = pathinfo($file['name']);
    $ftype = $pinfo['extension'];
    $destination = $destination_folder . str_shuffle(time() . rand(111111, 999999)) . '.' . $ftype;
    if (file_exists($destination) && $overwrite != true) {
    echo '同名文件已经存在了';
    die;
    }
    if (!move_uploaded_file($filename, $destination)) {
    echo '移动文件出错';
    die;
    }
    $pinfo = pathinfo($destination);
    $fname = $pinfo['basename'];
    echo $_W['attachurl'].$fname;
    @(require_once IA_ROOT . '/framework/function/file.func.php');
    @($filename = $fname);
    @file_remote_upload($filename);
    }

    主要修改格式服务器图片

    $f_slide = htmlspecialchars_decode($_REQUEST['f_slide']);
    $array =json_decode($f_slide);//转数组

    $object =json_decode(json_encode($array),true);

    $data = array(
    "uniacid"=>$uniacid,
    "f_slide"=>serialize($object),

    );

  • 相关阅读:
    Namenode主节点停止报错 Error: flush failed for required journal
    IntelliJ IDEA2018.3 最新破解方法
    idea 中解决maven 包冲突的问题(maven helper)
    java中的守护线程
    synchronized锁住的是代码还是对象
    maven package,clean,install,compile命令
    设计模式——装饰者模式
    设计模式——观察者模式
    com.alibaba.fastjson.JSON对类对象的序列化与反序列化
    java8 Stream使用案例
  • 原文地址:https://www.cnblogs.com/isuansuan/p/9957471.html
Copyright © 2011-2022 走看看