微信小程序上传图片到微擎

//图片上传
	public function doPageUpload(){
		global $_GPC, $_W;
		$uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png');
        $max_file_size = 2000000; //上传文件大小限制, 单位BYTE
        $destination_folder = "../attachment/".$_GPC['m']."/"; //上传文件路径
        if (!is_uploaded_file($_FILES["upfile"]['tmp_name']))
        //是否存在文件
        {
            echo "图片不存在!";
            exit;
        }
        $file = $_FILES["upfile"];
        if ($max_file_size < $file["size"])
        //检查文件大小
        {
            echo "文件太大!";
            exit;
        }
        if (!in_array($file["type"], $uptypes))
        //检查文件类型
        {
            echo "文件类型不符!" . $file["type"];
            exit;
        }

        if (!file_exists($destination_folder)) {
            mkdir($destination_folder);
        }
        $filename = $file["tmp_name"];
        $pinfo = pathinfo($file["name"]);
        $ftype = $pinfo['extension'];
        $destination = $destination_folder . str_shuffle(time() . rand(111111, 999999)) . "." . $ftype;
        if (file_exists($destination) && $overwrite != true) {
            echo "同名文件已经存在了";
            exit;
        }
        if (!move_uploaded_file($filename, $destination)) {
            echo "移动文件出错";
            exit;
        }
        $pinfo = pathinfo($destination);
        $fname = $pinfo['basename'];
        echo $fname;
        @require_once (IA_ROOT . '/framework/function/file.func.php');
        @$filename = $fname;
        @file_remote_upload($filename);
	}

 

selImg(e){
    let that = this;
    let name = e.currentTarget.dataset.name;
    let attachurl = that.data.attachurl;
    let uploadUrl = app.util.url('entry/wxapp/upload',{m:'duson_test'});
    wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
        success: function (res) {
            var tempFilePaths = res.tempFilePaths[0]
            wx.uploadFile({
                url: uploadUrl,
                filePath: tempFilePaths,
                name: 'upfile',
                formData: {},
                success: function (res) {
                    console.log(res)
                    if (name == 'head') {
                        let head_img = 'business.head_img';
                        that.setData({ [head_img]: res.data })
                    }
                    if (name == 'door') {
                        let door_photo = 'business.door_photo';
                        that.setData({ [door_photo]:  res.data })
                    }
                },
                fail: function (res) {
                    console.log('失败返回数据',res)
                },
            })
        }
    })
  },

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值