首页 >php教程 >php手册 >ThinkPHP 使用上传模块(ajaxFileUpload)

ThinkPHP 使用上传模块(ajaxFileUpload)

WBOY
WBOY原创
2016-06-07 11:36:251108浏览

ThinkPHP 使用上传模块(ajaxFileUpload)
下载Uploadfile类文件

http://www.thinkphp.cn/extend/224.html

放到:

ThinkPHP/Extend/Library/ORG/Net 。

修改文件头部,加上namespace:<?php<br /> namespace OrgNet; namespace OrgNet;官方文档位置:

http://doc.thinkphp.cn/manual/upload.html
$.ajaxFileUpload({<br /> url: _app_ &#039;/Products/Items/upload&#039;,<br /> secureuri: false,<br /> fileElementId: &#039;uploadId&#039;,<br /> dataType: &#039;json&#039;,<br /> data:$("form[name=fmAdd]").serializeArray(),<br /> success: function (data, status) {<br /> var data_obj = JSON.parse(data);<br /> console.log(data_obj);<br /> },<br /> error: function (data, status, e) {<br /> console.log(&#039;error&#039;);<br /> return;<br /> } <br /> }); javascript代码
$.ajaxFileUpload({public function upload(){<br /> if(!isset($this->U)){<br>         return array('result'=>'Timeout');<br>     }<br>     // import('Org.Net.UploadFile');<br>     $upload = new OrgNetUploadFile();<br>     //设置上传文件大小<br>     //$upload->maxSize = 3292200;<br>     //设置上传文件类型<br>     $upload->allowExts = explode(',', 'txt,csv');<br>     //设置附件上传目录<br>     $upload->savePath = './Uploads/';<br>     if (!$upload->upload()) {<br>       //捕获上传异常<br>       //$this->error($upload->getErrorMsg());<br>       $this->response(array("result"=>"Fail"),'json');<br>     } else {<br>       //取得成功上传的文件信息<br>       $uploadList = $upload->getUploadFileInfo();<br>       $savename = $uploadList[0]['savename'];<br>       $this->response(array("result"=>"Success","url"=>$savename ),'json');<br>     }   <br>   }                     url: _app_ '/Products/Items/upload',                     secureuri: false,<br>                     fileElementId: 'uploadId',<br>                     dataType: 'json',                     data:$("form[name=fmAdd]").serializeArray(),                     success: function (data, status) {                        var data_obj = JSON.parse(data);                        console.log(data_obj);                     },                     error: function (data, status, e) {                         console.log('error');                         return;                     }                       }); PHP代码public function upload(){     if(!isset($this->U)){         return array('result'=>'Timeout');     }     // import('Org.Net.UploadFile');     $upload = new OrgNetUploadFile();     //设置上传文件大小     //$upload->maxSize = 3292200;     //设置上传文件类型     $upload->allowExts = explode(',', 'txt,csv');     //设置附件上传目录     $upload->savePath = './Uploads/';     if (!$upload->upload()) {       //捕获上传异常       //$this->error($upload->getErrorMsg());       $this->response(array("result"=>"Fail"),'json');     } else {       //取得成功上传的文件信息       $uploadList = $upload->getUploadFileInfo();       $savename = $uploadList[0]['savename'];       $this->response(array("result"=>"Success","url"=>$savename ),'json');     }      }html代码                   选择文件允许文件类型:.txt .csv
       
 

AD:真正免费,域名 虚机 企业邮箱=0元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn