oop'e yeni geçtiğimde yazmıştım işini görür umarım
class upload {
public $hata = 0; // hata var mı?
public $dosya; // herşeyimiz
public $uzantilar = array(".jpg","jpeg",".gif",".png",".bmp"); // izin verilen dosya türleri - kullanım esnasında değiştirilebilir
public $hedef = ""; // kaydedilecek klasör. Değer girilirse sonunda "/" olması gerekir
public $durum; // 1 ise upload başarılı
public $isim;
public $sonisim;
function upload($x) {
$this->dosya = $x;
$this->isup = is_uploaded_file($this->dosya['tmp_name']) ? 1 : 0;
if(is_uploaded_file($this->dosya['tmp_name'])) {
$this->tur_kontrol();
$this->isim = $this->dosya['name'];
} else {
$this->hata = 3;
}
}
function tur($x) {
return strtolower(substr($x,-4));
}
function tur_kontrol() {
$uzantisi = $this->tur($this->dosya['name']);
$this->hata = (!in_array($uzantisi,$this->uzantilar)) ? 1 : 0 ;
}
function isim_degistir() {
$rastgele = rand(1000,9999);
$this->isim =$rastgele . $this->isim;
}
function thumb($thedef="" , $w=100 , $h=100){
if($this->hata != 0)
return 0;
$tkaynak = $this->dosya['tmp_name'];
if(!file_exists($tkaynak))
return 0;
if(empty($thedef))
$thedef = "t/" . $this->isim;
// Dosyanin genislik, yukseklik ve tur bilgilerini aliyoruz
$bilgi = getimagesize($tkaynak);
$gen = $bilgi[0];
$yuk = $bilgi[1];
$tur = $bilgi['mime'];
$im = imagecreatetruecolor($w,$h);
if($tur == "image/jpeg")
$imx = imagecreatefromjpeg($tkaynak);
elseif($tur == "image/png")
$imx = imagecreatefrompng($tkaynak);
elseif($tur == "image/gif")
$imx = imagecreatefromgif($tkaynak);
else
return 0;
imagecopyresampled($im,$imx,0,0,0,0,$w,$h,$gen,$yuk);
if($tur == "image/jpeg")
imagejpeg($im,$thedef);
elseif($tur == "image/png")
imagepng($im,$thedef);
elseif($tur == "image/gif")
imagegif($im,$thedef);
imagedestroy($im);
imagedestroy($imx);
return $thedef;
}
function watermark($dosya,$metod = "normal") {
if(empty($dosya))
$dosya = $this->hedef . $this->isim;
$damga = imagecreatefrompng("watermark.png");
$bilgi = getimagesize($dosya);
$tur = $bilgi['mime'];
if($tur == "image/jpeg")
$resim = imagecreatefromjpeg($dosya);
elseif($tur == "image/png")
$resim = imagecreatefrompng($dosya);
elseif($tur == "image/gif")
$resim = imagecreatefromgif($dosya);
else
return 0;
$dx = imagesx($damga);
$dy = imagesy($damga);
if($metod == "normal") {
imagecopy($resim,$damga,imagesx($resim) - $dx - 10, imagesy($resim) - $dy - 10,0,0,$dx,$dy);
} elseif( $metod == "doldur") {
imagesettile($resim,$damga);
imagefilledrectangle($resim, 0, 0, imagesx($resim), imagesy($resim), IMG_COLOR_TILED);
} elseif ($metod == "ortaalt") {
if(imagesx($resim) + 10 > $dx && imagesy($resim) + 10 > $dy)
imagecopy($resim,$damga,imagesx($resim) / 2 - $dx / 2, imagesy($resim) - $dy - 10,0,0,$dx,$dy);
} elseif($metod == "tamorta") {
if(imagesx($resim) + 5 > $dx && imagesy($resim) + 5 > $dy)
imagecopy($resim,$damga,imagesx($resim) / 2 - $dx / 2, imagesy($resim)/2 - $dy/2,0,0,$dx,$dy);
}
if($tur == "image/jpeg")
imagejpeg($resim,$dosya);
elseif($tur == "image/png")
imagepng($resim,$dosya);
elseif($tur == "image/gif")
imagegif($resim,$dosya);
imagedestroy($resim);
}
function bitir() {
if($this->hata == 0) {
if(@move_uploaded_file($this->dosya['tmp_name'], $this->hedef. $this->isim)) {
$this->durum = "1";
return $this->hedef . $this->isim;
} else {
$this->durum = "0";
$this->hata = 2;
}
}
}
function debug() {
switch ($this->hata) {
case 0:
echo "Hata yok";
break;
case 1:
echo "İzin verilmeyen Dosya Türü";
break;
case 2:
echo "Taşıma işlemi Başarısız";
break;
case 3:
echo "Hatalı Dosya";
break;
}
}
}
header("Content-Type: text/html; charset=utf-8");
$dosya = new upload($_FILES['dosya']);
$dosya->hedef = "a/";
$dosya->isim_degistir();
echo "<img src=".$dosya->thumb()."><br>";
echo "<img src=".$dosya->bitir().">";
$dosya->watermark("","normal");
$dosya->debug();son satırlarda nasıl kullanabileceğini anlarsın galiba; istersen sadece thumb fonksiyonunu da kullanabilirsin.
yardım lazım olursa msnimi biliyosun