class UpFile
{
public $FilePath = "./images";
public $FileType = array("image/jpeg","image/bmp","image/gif");
public $FileSize = 1000000;
function __construct($InputName)
{
$this->File = $InputName;
}
function UpLoadFile()
{
$this->UpType = $this->File["type"];//获取上传文件类型
$this->UpName = $this->File["name"];
$this->UpTmp_Name = $this->File["tmp_name"];
$this->UpSize = $this->File["size"];
if($this->UpSize > $this->FileSize)
{
echo "
";
echo "alert('上传文件太大!');";
echo "location.href='javascript:history.go(-1)';";
echo "
// -->";
}
if(!in_array($this->UpType,$this->FileType))
{
echo "
";
echo "alert('上传类型不正确 只能上传gif|jpg|png文件');";
echo "location.href='javascript:history.go(-1)';";
echo "
// -->";
}
if(!file_exists($this->FilePath))
{
mkdir($this->FilePath);
}
if($this->File["error"]==0)
{
$this->FileNameType = pathinfo($this->UpName);
$this->FileNameType = $this->FileNameType["extension"];
$this->FileName = $this->FilePath . "/" ."S_". date("Ymdhis") . "." .$this->FileNameType;
if(move_uploaded_file($this->UpTmp_Name,$this->FileName))
{
echo "
";
echo "alert('文件上传成功!');";
echo "location.href='javascript:history.go(-1)';";
echo "
// -->";
}
else
{
echo "
";
echo "alert('文件上传失败');";
echo "location.href='javascript:history.go(-1)';";
echo "
// -->";
}
}else
{
echo "
";
echo "alert('上传文件失败!');";
echo "location.href='javascript:history.go(-1)';";
echo "
// -->";
}
return $this->FileName;
}
}
?>
//调用
include_once("UpLoadFile.php");
if($_POST["submit"])
{
$InputName = $_FILES["UpFile"];
$UpFile = new UpFile($InputName);
$name = $UpFile->UpLoadFile();
$MyImage = new ImageReSize($name,"100","80","./images/");
$MyImage->GoReSize();
}
?>