曹え 5811 发布于:2024-01-09 03:12:53
// 图片上传 function actionUpimg(){ if (!$_FILES['file']['error']){ if ($_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/png'){ if ($_FILES['file']['size']<200000){ $pix = explode('.',$_FILES['file']['name']); $pix = end($pix); //文件传到文件夹中,可以拼接时间戳,用户名等防止文件名重复 $file_name = "image/".md5($this->u["id"]).'.'.$pix; move_uploaded_file($_FILES['file']['tmp_name'],$file_name); echo json_encode(['code'=>200,'msg'=>'上传成功', 'url'=>$img,'type'=>$_FILES['file']['type']]); exit(); }else{ exit(json_encode(array('code'=>0,'msg'=>'文件太大了,不能超过2M'))); } }else{ exit(json_encode(array('code'=>0,'msg'=>'文件格式错误,只能上传jpg和png格式图片','type'=>$_FILES['file']['type']))); var_dump($_FILES); } }else{ exit(json_encode(array('code'=>0,'msg'=>'上传失败'))); } }
登录后可以留言提问!
微信扫码登录