这是一个基于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元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
