Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as PHP by matheew ( 15 years ago )
<?php
/**
 * @ class.files.php
**/
class Class_Files {

 private $upload_dir;
 private $ext;
 private $mime;
 private $max_size;
 private $name;
 
 /**
 * @ funkcja __construct ( )
 * @ malo interesujace nas rzeczy
 **/
 
 public function __construct ( $max_size, $name, $upload_dir, $errors, $ext, $mime, $sign ) {
  $this->max_size = $max_size;
  $this->name = $name;
  $this->upload_dir = $upload_dir;
  $this->errors = $errors;
  $this->ext = $ext;
  $this->mime = $mime;
  $this->sign = $sign;
  $this->_DeleteFile&#40;&#41;;
 }
  
 /**
 * @ funkcja _CheckSizeFile &#40; $size &#41;
 * @ zmiana jednostek wielkosci pliku
 **/
 
 private function _CheckSizeFile &#40; $size &#41; {
  if($size >= 1073741824) {
   $size = @round($size / 1073741824 * 100) / 100 . " GB";
  } elseif($size >= 1048576) {
   $size = @round($size / 1048576 * 100) / 100 . " MB";
  } elseif($size >= 1024) {
   $size = @round($size / 1024 * 100) / 100 . " KB";
  } else { 
   $size = $size . " B";
  }
  $this->file_doc = $size;
 }
 
 /**
 * @ funkcja _CheckExtFile &#40; &#41;
 * @ sprawdza zgodnosc mozliwych rozszerzen pliku
 **/
 
 private function _CheckExtFile &#40; &#41; {

  if(in_array($this->file_ext, $this->ext) && in_array($this->file_type, $this->mime)) {
   return true;
  } else {
   return false;
  }
 }
 
 /**
 * @ funkcja _UploadFile &#40; &#41;
 * @ upload na serwer pliku
 **/
 
 public function _UploadFile &#40; &#41; {

  $this->_CheckUploadDir();
  $this->_UploadedNameFile&#40;&#41;;
  
  if(is_uploaded_file&#40;$this->file_tmp&#41;) {
  if($this->_CheckFileSize() == true) {
  if($this->_CheckExtFile&#40;&#41; == true) {
  if($this->_CheckNameFile&#40;&#41; != true) {
  if(move_uploaded_file&#40;$this->file_tmp, $this->upload_dir .'/'. $this->file_name&#41;) {
  
   mysql_query("INSERT INTO upload_files VALUES(0 ,'".$this->name_file."','".$this->file_doc."',
      '".$this->info ." (".$this->chmod.")','".$this->file_type."','".date("d-m-Y H:i")."')");
   echo $this->errors[2];
   
  }} else {
   echo $this->errors[5];
  }
  } else {
   echo $this->errors[1];
  } 
  } else {
   echo $this->errors[3]; 
  }
  } else {
   echo $this->errors[4]; 
  }
 }
 
 /**
 * @ funkcja _CheckFileSize ( )
 * @ sprawdza czy wielkosc pliku zgadza sie z dozwolona
 **/
 
 public function _CheckFileSize ( ) {
  if(is_numeric($this->file_size) && $this->file_size <= $this->max_size){
            return true;
        } else {
            return false;
        }
 }
 
 /**
 * @ funkcja _UploadedNameFile &#40; &#41;
 * @ przypisuje poszczegolnym zmiennym dane
 **/
 
 private function _UploadedNameFile &#40; &#41; {
  $this->file_name = $_FILES[$this->name]['name'];
  $this->name_file = $_FILES[$this->name]['name'];
  $this->file_size = $_FILES[$this->name]['size'];
  $this->file_tmp = $_FILES[$this->name]['tmp_name'];
  $this->file_type = $_FILES[$this->name]['type'];
  $this->file_ext = pathinfo($this->file_name, PATHINFO_EXTENSION);
  $this->_CheckSizeFile&#40;$this->file_size&#41;;
  $this->_FilePerms($this->file_tmp);
  $this->_ChangeNameFile&#40;&#41;;
 }
 
 /**
 * @ funkcja _ChangeNameFile &#40; &#41;
 * @ odpowiada za zmiane nazwy pliku
 **/
 
 private function _ChangeNameFile &#40; $dot = '.' &#41; {
  $this->file_name = md5(time().$this->file_name).$this->file_ext;
  $this->file_name = substr($this->file_name, 0, -27).$dot.$this->file_ext;
 }
 
 /**
 * @ funkcja _FilePerms ( )
 * @ sprawdza uprawienia pliku
 **/
 
 private function _FilePerms ( $file_tmp ) {
  $this->fileperms = fileperms( $file_tmp );

  if (($this->fileperms & 0xC000) == 0xC000) {
   $this->info = 's';
   $this->info = 'l';
  } elseif (($this->fileperms & 0x8000) == 0x8000) {
   $this->info = '-';
  } elseif (($this->fileperms & 0x6000) == 0x6000) {
   $this->info = 'b';
  } elseif (($this->fileperms & 0x4000) == 0x4000) {
   $this->info = 'd';
  } elseif (($this->fileperms & 0x2000) == 0x2000) {
   $this->info = 'c';
  } elseif (($this->fileperms & 0x1000) == 0x1000) {
   $this->info = 'p';
  } else {
     $this->info = 'u';
  }

  $this->info .= (($this->fileperms & 0x0100) ? 'r' : '-');
  $this->info .= (($this->fileperms & 0x0080) ? 'w' : '-');
  $this->info .= (($this->fileperms & 0x0040) ?
     (($this->fileperms & 0x0800) ? 's' : 'x' ) :
     (($this->fileperms & 0x0800) ? 'S' : '-'));

  $this->info .= (($this->fileperms & 0x0020) ? 'r' : '-');
  $this->info .= (($this->fileperms & 0x0010) ? 'w' : '-');
  $this->info .= (($this->fileperms & 0x0008) ?
     (($this->fileperms & 0x0400) ? 's' : 'x' ) :
     (($this->fileperms & 0x0400) ? 'S' : '-'));
     
  $this->info .= (($this->fileperms & 0x0004) ? 'r' : '-');
  $this->info .= (($this->fileperms & 0x0002) ? 'w' : '-');
  $this->info .= (($this->fileperms & 0x0001) ?
     (($this->fileperms & 0x0200) ? 't' : 'x' ) :
     (($this->fileperms & 0x0200) ? 'T' : '-'));
     
  $this->chmod = substr(decoct( fileperms($file_tmp) ), 3);
 }
 
 /**
 * @ funkcja _CheckNameFile&#40; &#41;
 * @ sprawdza jaki znak jest niedozwolony w nazwie
 **/
 
 private function _CheckNameFile &#40; &#41; {
  if(strpos($this->name_file, "'") || strpos($this->name_file, ';') || strpos($this->name_file, '/')) {
   return true;
  } else {
   return false;
  }
 }
 
 /**
 * @ funkcja _ ( )
 * @ sumuje wszytstkie rekordy z tabeli upload_files
 **/
 
 public function _SumRecords ( ) {
  $sum = mysql_query("select COUNT(*) from upload_files");
  return mysql_result($sum, 0);
 }
 
 /**
 * @ funkcja _DeleteFile &#40; &#41;
 * @ usuwa po id wskazany plik
 **/
 
 private function _DeleteFile &#40; &#41; {
  $delete = mysql_escape_string($_GET['delete_file']);
  if(is_numeric($delete)) {
   $mysql = mysql_query("SELECT COUNT(*) from upload_files WHERE id = '$delete'");
   if(mysql_result($mysql, 0) != 0) {
    //$fetch_array = mysql_fetch_array($mysql);
    mysql_query("delete from upload_files where id = '$delete'");
   }
  }
 }
 
 /**
 * @ funkcja _DownloadFile &#40; &#41;
 * @ pobiera po id wskazany plik
 **/
 
 private function _DownloadFile &#40; &#41; {
  //code
 }
 
 /**
 * @ funkcja _CheckUploadDir ( )
 * @ sprawdza czy istnieje folder podany na poczatku
 **/
 
 private function _CheckUploadDir ( ) {
  if(is_dir($this->upload_dir) == false) {
   mkdir ($this->upload_dir, 0644);
  }
 }
}
?>

 

Revise this Paste

Your Name: Code Language: