Home > php教程 > php手册 > 关于thinkphp文件上传函数的初步探究

关于thinkphp文件上传函数的初步探究

WBOY
Release: 2016-06-07 11:40:02
Original
1086 people have browsed it

这是一个基于thinkphp框架的一个文件上传函数,可以单独放在框架的公用函数里面,同时还可以返回文件的信息,使用说明很详细,希望能对大家有所帮助,有不对的地方,也请大家帮忙指导下,谢谢啊!
function upload(){<br> <br>         /*<br>             使用方法:<br>             1、$uploadInfo = upload(); 调用函数<br>             2、判断返回值是否为真,进行相应的提示和跳转<br>                 if ($uploadInfo) {<br>                        $this->success('上传成功!');<br>                    } else {<br>                        $this->error('上传失败!');<br>                    }<br>             3、$uploadInfo['photo']的值<br>                 array (size=9)<br>                   'name' => string '1.jpg' (length=5)<br>                   'type' => string 'image/jpeg' (length=10)<br>                   'size' => int 78646<br>                   'key' => string 'photo' (length=5)<br>                   'ext' => string 'jpg' (length=3)<br>                   'md5' => string 'c23173655f2ef9715c37b8448408f36f' (length=32)<br>                   'sha1' => string '388fabe45a33669bd2dcbb3ac8f214b702954e47' (length=40)<br>                   'savename' => string '20141210-54880fa2b14c1.jpg' (length=26)<br>                   'savepath' => string 'images/2014-12-10/' (length=18)<br>             4、获取文件的相关信息<br>                 $fileExt = $uploadInfo['photo']['ext']; // 文件后缀名<br>                 $filePath = $uploadInfo['photo']['savepath'].$uploadInfo['photo']['savename']; // 图片路径和名称<br>         */<br>         <br>         $upload = new \Think\Upload(); // 实例化上传类<br>         $upload->maxSize   =     3145728 ; // 设置附件上传大小<br>         $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg'); //  设置附件上传类型<br>         $upload->savePath  =     'images/'; // 设置附件上传目录<br>         $upload->saveName  =     date('Ymd',time()).'-'.uniqid(); // 直接设置上传文件名(日期 + 唯一值)<br> <br>         // 上传文件操作<br>         return $upload->upload();<br>     }

附件 function.rar ( 904 B 下载:15 次 )

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