Basit Resim Yükleme Sınıfı

PHP
68 lines
<?php
class resimYukle {
var $yol;
var $yeniresim;
var $uzanti;
var $resim;
var $hata;
var $yuklenen;
function tipKontrol(){
if((strcmp($this->resim['type'],'image/jpeg')==0)||(strcmp($this->resim['type'],'image/gif')==0)|| (strcmp($this->resim['type'],'image/pjpeg')==0)||(strcmp($this->resim['type'],'image/jpg')==0)||(strcmp($this->resim['type'],'image/x-png')==0)){
switch($this->resim['type']){
case 'image/jpg':
$this->uzanti = '.jpg';
break;
case 'image/jpeg':
$this->uzanti = '.jpg';
break;
case 'image/pjpeg':
$this->uzanti = '.jpg';
break;
case 'image/gif':
$this->uzanti = '.gif';
break;
case 'image/x-png':
$this->uzanti = '.png';
break;
}
return true;
}else{
$this->hata .= '<br>Bilinmeyen Resim Tipi '.$this->resim['type'];
return false;
}
}
function yukle($yeniyol,$resim,$yeniresim=''){
$this->yol = $yeniyol;
$this->resim = $resim;
$this->yuklenen = '';
if($yeniresim != ''){
$this->yeniresim = $yeniresim;
}else{
$this->yeniresim = $this->resim_adi;
}
$this->tipKontrol();
if($this->uzanti){
$resimFinal = $this->yol.$this->yeniresim.$this->uzanti;
if(copy($this->resim['tmp_adi'], $resimFinal)){
$this->yuklenen = $this->yeniresim.$this->uzanti;
return $resimFinal;
}else{
$this->hata .= '<br>'.$resimFinal.' kopyalanamadı.'.$this->yol.' yazma izinlerini kontrol edin';
return false;
}
}else{
$this->hata .= '<br>Uzantı alınamadı '.$this->uzanti;
return false;
}
}
}
if($_FILES){
$y = new resimYukle();
$y->yukle(getcwd().'/',$_FILES["file"],'yeni');
echo $y->hata;
}
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" adi="file">
<input type="submit" value="Yükle">
</form>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 

Sizin Değerli Görüşlerinize İhtiyacımız Var.