html代码:
js代码:
function doUpload() { $.ajaxFileUpload({ url: "index.php?m=Jwgl&c=ManagerCompetition&a=upload", secureuri: false, fileElementId : ['fjtitle','uploadForm','fjDescribe'], dataType: 'json', type:"POST", data:$("#fjtitle").serializeArray(), success: function (data) { if(data.status == '1') { alert(data.message); } else { alert(data.message); } }, error: function (data) { alert('error'); return; } }); } 后台代码:
public function upload(){ //这里可以去input标签中的文本 $title = I('fjtitle');//等 // if(!isset($this->U)){ // return array('result'=>'Timeout'); // } // import('Org.Net.UploadFile'); $upload = new \Org\Net\UploadFile(); //设置上传文件大小 //$upload->maxSize = 3292200; //设置上传文件类型 $upload->allowExts = explode(',', 'txt,csv,png,jpg,xlsx'); //设置附件上传目录 $upload->savePath = './Uploads/'; if (!$upload->upload()) { //捕获上传异常 $res['status'] = '0'; $res['message'] = '上传失败'; } else { //取得成功上传的文件信息 $uploadList = $upload->getUploadFileInfo(); $savename = $uploadList[0]['savename']; $res['status'] = '1'; $res['message'] = '上传成功...'; $res['fileName'] = $savename; } echo json_encode($res); }