<?php
/*
* @author Amine
* @copyright 2011
* @site :
www.frmways2.com * upload image class
*/
class upload_file{
/**
* downloads direction
*/
public $dir;
/**
* max file size
*/
public $max=1000000;
/**
* allow ex
*/
protected $Ex=array(".png",".gif",".zip"); // الملفات المتآحة
/**
* method to get file name
*/
protected $F_Name;
/**
* method to get file type
*/
protected $F_Type;
/**
* method to get file size
*/
protected $F_Size;
/**
* method for the folder where the file download in
*/
protected $F_Tmp;
/**
* method to create a random name for the file
*/
protected $new_name="qwertyuiopasdfghjklmnbvcxz1234567890";
///////////////////////////////////////////////
function __construct($folder,$method){
if(!is_dir($folder)){
mkdir($folder);
echo "Done";
}
$this->dir=$folder;
$this->F_Name = $_FILES[$method]['name'];
$this->F_Type = $_FILES[$method]['type'];
$this->F_Size = $_FILES[$method]['size'];
$this->F_Temp = $_FILES[$method]['tmp_name'];
}
/**
* function to check file type
*/
function check_file_type(){
$l= strtolower(strstr($this->F_Name,'.'));
if(!in_array($l,$this->Ex))
return false;
}
/**
* function to check file size
*/
function check_file_size(){
if($this->F_Size > $this->max){
return "the size is too big";
}
}
/**
* function to create new name for the file
*/
function new_name(){
return substr(str_shuffle($this->new_name."png"),0 , 6);
}
/**
* function to upload the file
*/
function up(){
move_uploaded_file($this->F_Temp,$this->dir.$this->new_name().$this->F_Name);
return true;
}
}
?>