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

ThinkPHP 使用上传模块(ajaxFileUpload)

WBOY
WBOY原創
2016-06-07 11:36:251107瀏覽

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

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

放到:

ThinkPHP/Extend/Library/ORG/Net 。

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

http://doc.thinkphp.cn/manual/upload.html

javascript代码$.ajaxFileUpload({<br>                     url: _app_+'/Products/Items/upload',<br>                     secureuri: false,<br>                     fileElementId: 'uploadId',<br>                     dataType: 'json',<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('error');<br>                         return;<br>                     }      <br>                 });
PHP代码public function upload(){<br>     if(!isset($this->U)){<br>         return array('result'=>'Timeout');<br>     }<br>     // import('Org.Net.UploadFile');<br>     $upload = new \Org\Net\UploadFile();<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>   }html代码 <form> <br>        <table> <br>           <tr> <th>选择文件</th> <td> <input>允许文件类型:.txt .csv</td> </tr> <br>        </table> <br>  </form>

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

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn