<?php
class file_upload
{
var $filename;
var $filessize;
var $filestype;
var $filenewname;
var $filetmpname;
var $files;
// var $types;
var $path;
var $allowtype;
var $allowsize;
var $fileerror;
var $seterror;
function __construct($files,$path)
{
$this->filename=$files['name'];
$types=explode(".",$this->filename);
$this->filestype=$types[count($types)-1];
$this->filessize=$files['size'];
$this->fileerror=$files['error'];
$this->allowtype=array("jpg","png","gif","jpeg");
$this->allowsize=2000000;
$this->filenewname=time().".".$this->filestype;
$this->filetmpname=$files["tmp_name"];
$this->path=$path;
$this->seterror=1;
if($this->fileerror!=0)
{
switch($this->fileerror)
{
case 1:$this->seterror="文件大小超出了服务器的空间大小";break;
case 2: $this->seterror="上传的文件大小超出浏览器的限制";break;
case 3: $this->seterror="文件只有部分被上传";break;
case 4: $this->seterror= "文件没有被上传";break;
case 6: $this->seterror="找不到临时文件夹";break;
case 7: $this->seterror= "文件写入失败";break;
}
}
else
{
if(!in_array($this->filestype,$this->allowtype))
{
$this->seterror="文件类型不符合";
}
else
{
if($this->filessize>$this->allowsize)
{
$this->seterror="上传文件超出限制";
}
else
{
if(!is_uploaded_file($this->filetmpname))
{
$this->seterror="非法操作";
}
else
{
if(!file_exists($this->path))
{
mkdir($this->path,0777);
}
else
{
if($this->seterror!=1)
{
echo $this->seterror="上传失败";
exit;
}
else
{
//echo "ssss";
move_uploaded_file($this->filetmpname,$this->path.$this->filenewname);
}
}
}
}
}
}
}
function getpath()
{
return $this->path.$this->filenewname;
}
}
?>
浙公网安备 33010602011771号