Home > php教程 > php手册 > body text

ThinkPHP 使用上传模块(ajaxFileUpload)

WBOY
Release: 2016-06-07 11:36:25
Original
1096 people have browsed it

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元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template