<?php
/* D3Upload File Upload Class v1.0 [13.10.2009] */
# First version of class has many options to upload. Permitted file extensions, upload dir, file size and file type variables are added.
# D3Upload is Construct Function.
# Value from form must be $dosya=new D3Upload('Value');
# Error codes has been added in switch
# Error Description is a different function.
# Files name will be changed as time() format name, number and unique
class D3Upload{
var $inputName; // <input name value
var $fileName; // original file name
var $tmpName; // fine name in tmp folder
var $type; // file type
var $size; // File Size as GB TB MB
var $sizeAsKb; // File Size as KB
var $error; // Error if exist
var $uzanti; // File Extensions
var $izinliler=Array(); // Permitted file extensions
var $sonuc; // Result
function D3Upload($inputName){
$dosya=$_FILES[$inputName];
// Filling class variables.
$this->inputName=$inputName;
$this->fileName=$dosya['name'];
$this->tmpName=$dosya['tmp_name'];
$this->type=$dosya['type'];
$this->size=$dosya['size'];
$this->error=$dosya['error'];
$this->uzanti=end(explode('.',$this->fileName));
}
function upload($dir,$dosya_adi=False,$unique=False){ // is main upload function
$this->error=in_array($this->uzanti,$this->izinliler) ? 0 : 99;
$this->error=is_dir($dir)? $this->error : 98;
$this->error=is_writable($dir) ? $this->error : 97;
switch($this->error){
case 0:
$dosya_son_adi=$unique ? time().'.'.$this->uzanti : ($dosya_adi ? $dosya_adi.'.'.$this->uzanti : $this->fileName);
if(@copy($this->tmpName,$dir.'/'.$dosya_son_adi)){
$this->sonuc=$dosya_son_adi;
return $this;
}else {
$this->sonuc=False;
return $this;
}
return $this;
case 4:
return $this->hata('Dosya Seçmediniz. Hata Kodu: '.$this->error); // Error: No file selected
case 99:
return $this->hata($this->uzanti.' İzin verilen bir dosya tipi deÄilr Hata Kodu : '.$this->error);
break;
case 98:
return $this->hata($dir.' Geçerli Bir Klasör DeÄil'); // Error: is not a folder
break;
case 97:
return $this->hata($dir.' Yazılabilir DeÄil.!'); // Error: folder is not writable
break;
default:
return $this->hata('Bilinmeyen Hata Kodu : '.$this->error); // Error: Unknown Error ( General Error )
break;
}
}
function izinli($uzantilar){
$this->izinliler=explode(',',$uzantilar);
return $this;
}
function hata($aciklama){
die($aciklama);
}
}
?>