$this->upfile_name = $upfile_name;
$this->upfile_size = $upfile_size;
$this->new_upfile_name = $this->createnewfilename($this->upfile_name);
$this->f1 = public/upload/images;
$this->f2 = $this->f1./.date('y').-.date('m');
$this->f3 = $this->f2./.date('d');
$this->filename = $this->f3 . / . $this->new_upfile_name;
$this->maxsize = 5000*1024; # 文件大小 5000kb
$this->file_type = gif/jpg/jpeg/png/bmp; # 允许上传的文件类型
}
# 创建新文件名 (原文件名)
function createnewfilename($file_name){
$this->fleth = explode(.,$file_name);
$this->fileextent = $this->fleth[(int)count($this->fleth)-1]; # 获取文件后缀;
$tmps教程tr = date('ymd').rand(0,time()) . . .$this->fileextent; # 创建新文件名;
return $tmpstr;
}
# 检测文件类型是否正确
function chk_fileextent(){
$iwtrue = 0;
$fle = explode(/,$this->file_type);
for($i=0; $i if($this->fileextent == $fle[$i]){
$iwtrue = (int) $iwtrue + 1;
}
}
if( $iwtrue == 0 ){
$this->msg(文件不符合 .$this->file_type. 格式!);
}
}
# 提示错误信息并终止操作
function msg($error){
echo ;
die();
}
# 保存文件
function savefile(){
$this->chk_fileextent();
$this->chk_filesize();
$this->createfolder( ./.$this->f1 );
$this->createfolder( ./.$this->f2 );
$this->createfolder( ./.$this->f3 );
return $this->chk_savefile();
}
# 检测上传结果是否成功
function chk_savefile(){
$copymsg = copy($this->upfile,./.$this->filename);
if( $copymsg ){
return $this->filename;
}
else{
$this->msg(文件上传失败! 请重新上传! );
}
}
# 创建文件夹
function createfolder($foldername){
if( !is_dir($foldername) ){
mkdir($foldername,0777);
}
}
# 检测文件大小
function chk_filesize(){
if( $this->upfile_size > $this->maxsize ){
$this->msg(目标文件不能大于. $this->maxsize/1024 . kb);
}
}
# 删除文件($filepath 文件相对路径)
function deletefile($filepath){
if( !is_file($filepath) ){
return false;
}
else{
$ending = @unlink($filepath);
return $ending;
}
}
}
?>