[php]
<?php
header("Content-Type:text/html; charset=utf-8;");
echo "uploadclass<br/>";
echo "<br/>".$_FILES['file']["name"]."<br/>";
$nabc = new uploadclass($_FILES['file']);
echo "<br/>".$nabc->getname()."<br/>";//獲取新的名字
class uploadclass {
var $location ;//設置存放文件的目錄
var $max_size;//上傳文件的大小
var $event; //初始值是success
var $filename;//獲取保存在文件夾裡的文件的文件名字
function uploadclass($file) {
$location = "./temp/";//設置存放文件的目錄
$max_size = 1000000;//上傳文件的大小
$event="success"; //初始值是success
//判斷目錄是否存在
if(! is_dir($location))
{
mkdir($location);
@chmod($location,777);
}
$oldFilename = $file["name"];
$filename = explode(".",$oldFilename);
$filenameext = $filename[count($filename) - 1];
$newFilename = "_".time()."_".rand(10000, 20000).".".$filenameext;
$this->filename = $newFilename;
echo "<br/>".$this->$filename."<br/>";
if(!$file['name']=="")
{
if($file['size']<$max_size)
{
echo "文件上傳路徑:".$location.$file['name'];
move_uploaded_file($file['tmp_name'], $location.$newFilename) or $event = "Failure";
}
else
{
$event="File too large";
}
}
}
public function getname()
{
return $this->filename;
}
}
?>