up.class.php
f=$f;
$this->s=$s*1000000;
$this->n=$n;
$this->d=$d;
$this->loading();
}
function loading(){
$this->fsize();
$this->ftype();
$this->fmv();
}
function fname(){
if($this->n){
return $this->n.$this->ftype();
}else{
return time().rand(111,999).$this->ftype();
}
}
function fdir(){
if($this->d){ //判断用户是否指定文件夹名
if(!is_dir($this->d)){ //判断指定的文件夹名是否存在
mkdir($this->d);
}
return $this->d./;
}else{
if(!is_dir(date(ymd))){
mkdir(date(ymd));
}
return date(ymd)./;
}
} //end fdir
function fsize(){
if($this->f['size']>$this->s){
echo 文件超过大小;
exit();
}else{
return true;
}
}
function ftype(){
switch($this->f['type']){
case image/x-png: $ok=.png;
break;
case image/png: $ok=.png;
break;
case application/pdf: $ok=.pdf;
break;
case image/pjpeg: $ok=.jpg;
break;
case image/jpeg: $ok=.jpg;
break;
case image/jpg: $ok=.jpg;
break;
default: $ok=false;
break;
}
if($ok){
return $ok;
}else{
echo 文件类型不正确;
exit();
}
}
function fmv(){
move_uploaded_file($this->f['tmp_name'],$this->fdir().$this->fname());
}
}
?>
test.php 上传文件
$v){
new up($_files[$id]);
}
}
?>