maxSize = 3145728 ;// 设置附件上传大小 $upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 $upload->rootPath = C('IMG_PATH'); // 设置附件上传根目录 $upload->saveName = array('uniqid',''); $upload->autoSub = true; //是否使用子目录保存上传文件 $upload->subName = array('date', 'Y-m'); //子目录创建方式,默认为hash,可以设置为hash或者date $info = $upload->upload($_FILES); // 上传文件 if(!$info) {// 上传错误提示错误信息 //$data = array('code'=>1,'msg'=>'文件上传错误'); $data = array('code'=>1,'msg'=>$upload->getError(),'data'=>$_FILES['file_data']); $this->returnData($data);exit; }else{// 上传成功 获取上传文件信息 $img_path = str_replace('.', '', C('IMG_PATH')).$info['file_data']['savepath'].$info['file_data']['savename']; $data = array( 'img_path'=>C('DOMAIN').$img_path, 'img_url'=>C('DOMAIN').$img_path, ); $data = array('code'=>0,'msg'=>'','data'=>$data); $this->returnData($data);exit; } } }