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
* @ copyright Mateusz Wróblewski
**/
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 ) {
$this->max_size = $max_size;
$this->name = $name;
$this->upload_dir = $upload_dir;
$this->errors = $errors;
$this->ext = $ext;
$this->mime = $mime;
}
/**
* @ funkcja _CheckSizeFile ( $size )
* @ zmiana jednostek wielkosci pliku
**/
private function _CheckSizeFile ( $size ) {
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 ( )
* @ sprawdza zgodnosc mozliwych rozszerzen pliku
**/
private function _CheckExtFile ( ) {
if(in_array($this->file_ext, $this->ext) && in_array($this->file_type, $this->mime)) {
return true;
} else {
return false;
}
}
/**
* @ funkcja _UploadFile ( )
* @ upload na serwer pliku
**/
public function _UploadFile ( ) {
$this->_CheckUploadDir();
$this->_UploadedNameFile();
if(is_uploaded_file($this->file_tmp)) {
if($this->_CheckFileSize() == true) {
if($this->_CheckExtFile() == true) {
if(move_uploaded_file($this->file_tmp, $this->upload_dir .'/'. $this->file_name)) {
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[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 ( )
* @ przypisuje poszczegolnym zmiennym dane
**/
private function _UploadedNameFile ( ) {
$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($this->file_size);
$this->_FilePerms($this->file_tmp);
$this->_ChangeNameFile();
}
/**
* @ funkcja _ChangeNameFile ( )
* @ odpowiada za zmiane nazwy pliku
**/
private function _ChangeNameFile ( $dot = '.' ) {
$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 _TableClassName ( )
* @ nadaje nazwe tabeli
**/
public function _TableClassName ( $mime ) {
if( strpos('audio', $mime) == true ) {
$this->table = 'music';
} elseif( strpos('video', $mime) == true ) {
$this->table = 'movie';
} elseif( stropos('image', $mime) == true ) {
$this->table = 'image';
} elseif( strpos('text', $mime) == true ) {
$this->table = 'txt';
} else {
$this->table = 'file';
}
return $this->table;
}
/**
* @ 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
Children: 35824