Home > Backend Development > PHP Tutorial > thinkphp实现不了rar文件的上传,希望大家指点一下,该怎么解决

thinkphp实现不了rar文件的上传,希望大家指点一下,该怎么解决

WBOY
Release: 2016-06-13 10:26:21
Original
1022 people have browsed it

thinkphp实现不了rar文件的上传,希望大家指点一下
thinkphp实现文件上传,rar格式的不能上传,pdf,jpg,xls文件可以上传
 

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->   public function upload(){       if(!empty($_FILES)){           echo 'ok';           dump($_FILES);           //如果有文件上传,上传附件            $this->_upload();                   }       else{           echo 'no';           dump($_FILES);       }          }
Copy after login

在提交rar格式文件后,判断提交的数据是空的;
倘若是提交pdf,jpg,xls文件,则判断提交的数据是正常,并且上传成功的

------解决方案--------------------
PHP code
Public function upload(){import('ORG.Net.UploadFile');$upload = new UploadFile();// 实例化上传类$upload->maxSize  = 3145728 ;// 设置附件上传大小$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型$upload->savePath =  './Public/Uploads/';// 设置附件上传目录if(!$upload->upload()) {// 上传错误提示错误信息$this->error($upload->getErrorMsg());}else{// 上传成功 获取上传文件信息$info =  $upload->getUploadFileInfo();} // 保存表单数据 包括附件数据$User = M("User"); // 实例化User对象$User->create(); // 创建数据对象$User->photo = $info[0]['savename']; // 保存上传的照片根据需要自行组装$User->add(); // 写入用户数据到数据库$this->success('数据保存成功!');}<br><font color="#e78608">------解决方案--------------------</font><br>tp里面自带的上传不支持rar格式的文件上传,你可以自己自己写一个上传类来实现<br><br>
Copy after login
探讨

PHP code
Public function upload(){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 3145728 ;// 设置附件上传大小
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg'……

------解决方案--------------------
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template