<?php
/**
* 文件上传类
* @author shuangyulin
* @author URL:www.shuangyulin.com
* @version 1.0
* @final 2013-02-04
*/
class upFiles
{
/**
* 上传的文件信息
* @var array
*/
public $uploadFiles = array();
/**
* 保存文件路径
* @var string
*/
public $saveFilePath;
/**
* 最大文件大小
* @var int
*/
public $maxFileSize;
/**
* 错误信息
* @var string
*/
public $lastError;
/**
* 默认充许上传的文件类型
* @var array
*/
public $allowType = array('gif','jpg','png','bmp');
/**
* 最终保存的文件名称
* @var string
*/
public $finalFile;
/**
* 返回已经上传文件的详细信息
* @var array
*/
public $saveFileInfo = array();
/**
* 构造函数,初始化相关信息,包括文件内容,上传地址,文件最大限制,文件类型
* @param array $file
* @param string $path
* @param int $size
* @param array $type
*/
public function __construct($file, $path, $size, $type)
{
$this->uploadFiles = $file;
$this->saveFilePath = $path;
$this->allowType = $type;
$this->maxFileSize = $size;
}
public function upload()
{
if (is_array($this->uploadFiles['name']))
{
for($i=0;$i<count($this->uploadFiles['name']);$i++)
{
//如果文件上传没有出现错误
if($this->uploadFiles['error'][$i] == 0)
{
//获取当前文件名,临时文件名,文件大小,扩展名
$name = $this->uploadFiles['name'][$i];
$tmpname = $this->uploadFiles['tmp_name'][$i];
$size = $this->uploadFiles['size'][$i];
$minetype = $this->uploadFiles['type'][$i];
$type = $this->getFileExt($this->uploadFiles['name'][$i]);
//检查文件大小是否合法
if(!$this->checkSize($size))
{
$this->lastError = "文件大小超出限制.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//检查文件扩展名是否合法
if(!$this->checkType($type))
{
$this->lastError = "非法的文件类型.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//检测当前文件是否非法提交
if(!is_uploaded_file($tmpname))
{
$this->lastError = "上传文件无效.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//移动后的文件名称
$basename = $this->getBaseName($name,'.'.$type);
//上传文件重新命名
list($usec, $sec) = explode(" ",microtime());
$savename = substr($usec,2).'.'.$type;
//创建上传文件的文件夹
createdir($this->saveFilePath);
$dir1 = $this->saveFilePath.'/'.date('Y');
createdir($dir1);
$dir2 = $this->saveFilePath.'/'.date('Y').'/'.date('m');
$thumb_dir = $dir2.'/thumb';
$cover_dir = $dir2."/cover";
createdir($dir2);
createdir($thumb_dir);
createdir($cover_dir);
//最终组合的文件路径
$this->finalFile = $dir2.'/'.$savename;
//把上传的文件从临时目录移到目标目录
if(!move_uploaded_file($tmpname,$this->finalFile))
{
$this->$this->uploadFiles['error'][$i];
$this->printMsg($this->lastError);
continue;
}
//存储已经上传的文件信息
$tembasename = $this->getBaseName($savename,'.'.$type);
$FileInfo = array(
'name' => $name,
'type' => $type,
'minetype' => $minetype,
'file' => $this->finalFile,
'size' => $size,
'basename' =>$tembasename,
'savename' => $savename,
'path' => $dir2,
'thumb_dir' =>$thumb_dir."/",
'cover_dir' =>$cover_dir."/"
);
$this->saveFileInfo[] = $FileInfo;
}
}
}
else
{
if($this->uploadFiles['error'] == 0)
{
//获取当前文件名,临时文件名,文件大小,扩展名
$name = $this->uploadFiles['name'];
$tmpname = $this->uploadFiles['tmp_name'];
$size = $this->uploadFiles['size'];
$minetype = $this->uploadFiles['type'];
$type = $this->getFileExt($this->uploadFiles['name']);
//检查文件大小是否合法
if(!$this->checkSize($size))
{
$this->lastError = "文件大小超出限制.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//检查文件扩展名是否合法
if(!$this->checkType($type))
{
$this->lastError = "非法的文件类型.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//检测当前文件是否非法提交
if(!is_uploaded_file($tmpname))
{
$this->lastError = "上传文件无效.文件名称:".$name;
$this->printMsg($this->lastError);
continue;
}
//移动后的文件名称
$basename = $this->getBaseName($name,'.'.$type);
//上传文件重新命名
list($usec, $sec) = explode(" ",microtime());
$savename = substr($usec,2).'.'.$type;
//创建上传文件的文件夹
createdir($this->saveFilePath);
$dir1 = $this->saveFilePath.'/'.date('Y');
createdir($dir1);
$dir2 = $this->saveFilePath.'/'.date('Y').'/'.date('m');
$thumb_dir = $dir2.'/thumb';
$cover_dir = $dir2."/cover";
createdir($dir2);
createdir($thumb_dir);
createdir($cover_dir);
//最终组合的文件路径
$this->finalFile = $dir2.'/'.$savename;
//把上传的文件从临时目录移到目标目录
if(!move_uploaded_file($tmpname,$this->finalFile))
{
$this->$this->uploadFiles['error'];
$this->printMsg($this->lastError);
continue;
}
//存储已经上传的文件信息
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
双鱼林PHP基于MVC三层模式图书管理系统demo.zip (112个子文件)
php基于MVC三层模式图书管理系统demo运行演示.avi 61.54MB
.buildpath 174B
style.css 2KB
add_modify.css 1KB
login.css 1KB
desk.css 841B
manage.css 752B
about.css 725B
Thumbs.db 34KB
t_book.frm 9KB
t_bookclass.frm 8KB
t_admin.frm 8KB
TopTitle.gif 83KB
ico08.gif 2KB
ico29.gif 2KB
error_b.gif 1KB
window.gif 1KB
closed.gif 1KB
help.gif 1KB
dialog_mc.gif 1KB
go.gif 736B
icon_query.gif 687B
icon_alert.gif 680B
dialog_closebtn_over.gif 441B
dialog_closebtn.gif 388B
open.gif 366B
doc.gif 159B
print.gif 156B
ADD.gif 110B
icon_dialog.gif 92B
index.htm 0B
index.htm 0B
index.htm 0B
index.htm 0B
[强烈推荐] 超漂亮的仿腾讯弹出框效果(兼容主流浏览器).html 4KB
about.html 3KB
[强烈推荐] 超漂亮的仿腾讯弹出层效果(兼容主流浏览器).html 3KB
NoImage.jpg 30KB
15688400.jpg 26KB
dialog_bg.jpg 22KB
79494300.jpg 21KB
01844900.jpg 20KB
37044500.jpg 20KB
20074100.jpg 18KB
37111800.jpg 18KB
76514300.jpg 15KB
19957400.jpg 10KB
login.jpg 5KB
error.jpg 4KB
menu.jpg 2KB
print.jpg 2KB
Dialog.js 28KB
calendar.js 25KB
treemenu.js 4KB
ajax.js 4KB
alert.js 3KB
util.js 2KB
db.opt 61B
upload.class.php 10KB
BookUpdate.php 6KB
bookManage.php 5KB
bookAdd.php 5KB
BookAction.php 5KB
SqlHelper.class.php 4KB
BookService.class.php 4KB
BookClassService.class.php 3KB
BookClassAction.php 3KB
bookClassManage.php 2KB
BookClassUpdate.php 2KB
Book.class.php 2KB
AdminService.class.php 2KB
desk.php 2KB
login.php 2KB
bookClassAdd.php 2KB
changePassword.php 1KB
main.php 1KB
GetBook.php 1KB
changePasswordProcess.php 1KB
error.php 973B
ok.php 958B
GetBook.php 833B
loginProcess.php 525B
BookClass.class.php 505B
GetBookClass.php 496B
util.php 438B
FenyePage.class.php 407B
CheckLoginState.php 258B
logout.php 134B
index.php 44B
snap.png 109KB
dialog_ct.png 6KB
dialog_mc.png 4KB
dialog_cb.png 4KB
dialog_mlm.png 3KB
dialog_mrm.png 3KB
dialog_closebtn_over.png 3KB
dialog_footercenter.png 3KB
dialog_rt.png 3KB
dialog_lt.png 3KB
dialog_closebtn.png 3KB
共 112 条
- 1
- 2
资源评论
芝麻粒儿
- 粉丝: 5w+
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功