php 簡單文件圖片上傳類
這個文件上傳類可以上傳gif",".jpg",".jar",".jad",".mid",".mp3",".mid",".bmp",".wav",".rm",".wmv文件格式哦,如果你還想支持其它的話可以設計$this->file_type();就OK了,。
<?php
class upload{
var $file_type;
var $file_size;
var $file_name;
var $exname;
var $datetime;
function up($post_name,$path){
$this->file_name=$_FILES[$post_name]["name"];
$this->exname=strtolower(substr($this->file_name,strrpos($this->file_name,".")));
$this->file_size=$_FILES[$post_name]["size"];
$this->file_type=array(".gif",".jpg",".jar",".jad",".mid",".mp3",".mid",".bmp",".wav",".rm",".wmv");
$this->datetime=date("YmdHis");
if(!in_array($this->exname,$this->file_type)){
print("<script language='javascript'>");
print("alert('格式不支持!');");
print("history.back();");
print("</script>");
break;
}elseif($this->file_size>"50000"){
print("<script language='javascript'>");
print("alert('圖片大小不能超過50KB!');");
print("history.back();");
print("</script>");
break;
}else{
move_uploaded_file($_FILES[$post_name]["tmp_name"],$path.$this->datetime.$this->exname);
}
}
function fileName(){
$pic=$this->datetime.$this->exname;
return $pic;
}
}
?>