public function __construct($file,$dri,$zise){
//set value
$this->dri = $dri;
$this->file = $file;
$this->SISE = $zise;
$this->size = $file["size"];
// separate name and type
$Arr = explode(".",$file["name"]);
$this->name = $Arr[0];
$this->type = $Arr[1];
}
//Add type
public function addType($type){
array_push($this->TYPE,$type) ;
}
//Check accuracy of image file.
public function check(){
if($this->checkSize()&&$this->checkType()&&$this->checkError())
return true;
else
return false;
}
//Chack Size of image file.
public function checkSize(){
if($this->SISE < $this->size||0 > $this->size) return false;
else return true;
}
//Check Type of image file.
public function checkType(){
$b = false;
$count = count($this->TYPE);
while($count>0){
if($this->TYPE[$count-1]==$this->type){$b = true;
}
$count--;
}
return true;
}
//Check error of image file
public function checkError(){
if($file["error"]==0){
return true;
}
else{
return false;
}
}
//Chack name of image file
public function checkName(){
//will add "001" in end of name image file
if(!file_exists($this->dri.$this->name."00001.".$this->type)){
//set name of image
$this->NAME = $this->name."00001.".$this->type;
}
else{
$b=true; $i=1;
while($b){
$num = $this->name.(str_pad(($i++),5,"0",STR_PAD_LEFT));
if(!file_exists($this->dri.$num.".".$this->type)){
//set name of image
$this->NAME = $num.".".$this->type;
// out loop
$b=false;
}
}
}
}
//Upload image
public function upImage(){
if($this->check()){
$this->checkName();
$move = move_uploaded_file($this->file["tmp_name"],$this->dri.$this->NAME);