function upload(){
/*
使用方法:
1、$uploadInfo = upload(); 调用函数
2、判断返回值是否为真,进行相应的提示和跳转
if ($uploadInfo) {
$this->success('上传成功!');
} else {
$this->error('上传失败!');
}
3、$uploadInfo['photo']的值
array (size=9)
'name' => string '1.jpg' (length=5)
'type' => string 'image/jpeg' (length=10)
'size' => int 78646
'key' => string 'photo' (length=5)
'ext' => string 'jpg' (length=3)
'md5' => string 'c23173655f2ef9715c37b8448408f36f' (length=32)
'sha1' => string '388fabe45a33669bd2dcbb3ac8f214b702954e47' (length=40)
'savename' => string '20141210-54880fa2b14c1.jpg' (length=26)
'savepath' => string 'images/2014-12-10/' (length=18)
4、获取文件的相关信息
$fileExt = $uploadInfo['photo']['ext']; // 文件后缀名
$filePath = $uploadInfo['photo']['savepath'].$uploadInfo['photo']['savename']; // 图片路径和名称
*/
$upload = new \Think\Upload(); // 实例化上传类
$upload->maxSize = 3145728 ; // 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
$upload->savePath = 'images/'; // 设置附件上传目录
$upload->saveName = date('Ymd',time()).'-'.uniqid(); // 直接设置上传文件名(日期 + 唯一值)
// 上传文件操作
return $upload->upload();
}
function.rar ( 904 B 下载:13 次 )