微擎小程序端上传图片 php后端接收图片 public function upload_header_img() { global $_GPC, $_W; $uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png'); $max_file_size = 10000000; //上传文件大小限制, 单位BYTE $send_path = "images/".date('Y-m-d')."/"; $destination_folder = ATTACHMENT_ROOT.$send_path; //上传文件路径 $result = array(); $result['code'] = 1; load()->func('file'); mkdirs($destination_folder); //fileinfo 检测begin /* $fip = finfo_open(FILEINFO_MIME_TYPE); $min_result = finfo_file($fip , $_FILES['upfile']['tmp_name']); fclose( $fip ); $min_type_arr = array(); $min_type_arr[] = 'image/jpeg'; $min_type_arr[] = 'image/gif'; $min_type_arr[] = 'image/jpg'; $min_type_arr[] = 'image/png'; $min_type_arr[] = 'video/mp4'; if( !in_array($min_result , $min_type_arr ) ) { die(); }*/ //fileinfo 检测end if (!is_uploaded_file($_FILES["upfile"]['tmp_name'])) //是否存在文件 { $result['msg'] = "图片不存在!"; echo json_encode($result); exit; } $file = $_FILES["upfile"]; if ($max_file_size < $file["size"]) //检查文件大小 { $result['msg'] = "文件太大!"; echo json_encode($result); exit; } if (!in_array($file["type"], $uptypes)) //检查文件类型 { $result['msg'] = "文件类型不符!" . $file["type"]; echo json_encode($result); exit; } $filename = $file["tmp_name"]; $pinfo = pathinfo($file["name"]); $ftype = $pinfo['extension']; $file_name = str_shuffle(time() . rand(111111, 999999)) . "." . $ftype; $destination = $destination_folder . $file_name; if (!move_uploaded_file($filename, $destination)) { $result['msg'] = "移动文件出错!"; echo json_encode($result); exit; } $pinfo = pathinfo($destination); $fname = $pinfo['basename']; //6956182894169131.png $thumb = file_image_thumb_resize($send_path.$file_name, 200); $thumb = str_replace(ATTACHMENT_ROOT , '', $thumb); $image_thumb = tomedia( $thumb ); $image_o = $send_path.$file_name; echo json_encode( array('code' => 0,'image_thumb' => $image_thumb, 'image_o' => $image_o , 'image_o_full' => tomedia($image_o) ) ); die(); }小程序端 wx.uploadFile({ url: app.util.url('entry/wxapp/index', { 'm': 'lionfish_comshop', 'controller': 'user.upload_header_img' }), filePath: avatarUrl, name: 'upfile', formData: { 'name': avatarUrl }, header: { 'content-type': 'multipart/form-data' }, success: function (res) { wx.hideLoading(); var data = JSON.parse(res.data); // const { image_thumb } = data; // console.log(that.data.avatarUrl) that.setData({ avatarUrl:data.image_thumb, }) // console.log(that.data.avatarUrl) } })
jshgtfrddh2年前0
你的文章让我感受到了不一样的视角,非常精彩。 https://www.yonboz.com/video/84282.htmlukfbunfxqk2年前0
你的文章让我感受到了不一样的视角,非常精彩。 https://www.yonboz.com/video/23752.htmldmtrqccbnn2年前0
你的文章内容非常卖力,让人点赞。 http://www.55baobei.com/l1t7Yd5s6H.htmlxsuhtbbzmm2年前0
你的文章让我感受到了不一样的视角,非常精彩。 https://www.4006400989.com/qyvideo/92199.htmlceskjhtfrd2年前0
你的文章内容非常卖力,让人点赞。 http://www.55baobei.com/l1t7Yd5s6H.html