上传
<meta charset="utf-8"/>
<?php
class upload{
var $filename;
var $filetype;
var $filesize;
var $fileerror;
public $filenewname;
var $allowsize;
var $allowtype;
var $path;
var $filetmpname;
var $seterror;
function __construct($files,$path)
{
$this->filename=$files['name'];
$types=explode(".",$this->filename);
$this->filetype=$types[count($types)-1];
$this->filesize=$files['size'];
$this->fileerror=$files['error'];
$this->allowtype=array("jpg","jpeg","gif","png","bmp");
$this->allowsize=20000000;
$this->filenewname=time().".".$this->filetype;
$this->filetmpname=$files['tmp_name'];
$this->path=$path;
$this->seterror=1;
if($this->fileerror!=0)
{
switch($this->fileerror)
{
case 1:;
case 2: $this->seterror= "上传的文件过大,最大为2M";exit;break;
case 3: $this->seterror= "部分文件被上传";exit;break;
case 4: $this->seterror= "文件没有被上传";exit;break;
case 6: $this->seterror="找不到临时文件夹";exit;break;
case 7: $this->seterror="文件写入失败";exit;break;
}
}
else
{
if(!is_uploaded_file($this->filetmpname))
{
$this->seterror="非法操作";exit;
}
else
{
if(!in_array($this->filetype,$this->allowtype))
{
$this->seterror="文件类型不符";exit;
}
else
{
if($this->filesize>$this->allowsize)
{
$this->seterror="超出最大限制";
exit;
}
else
{
if(!file_exists($this->path))
{
mkdir($this->path,0777);
}
else
{
if($this->seterror!=1)
{
echo $this->seterror;
//echo "1";
exit;
}
else
{
//echo "2";
//exit;
move_uploaded_file($this->filetmpname,$this->path.$this->filenewname);
}
}
}
}
}
}
}
function getpathname()
{
return $this->path.$this->filenewname;
}
}
?>

浙公网安备 33010602011771号