• 09-08-2010, 16:43:10
    #1
    R10'a Teşekkürler
    Yeni yeni php öğrenme yolunda ilerlediğim için sık sık sorularım oluyor kusura bakmayın ama r10'a çok teşekkür ederim gerçekten sayenizde öğreniyorum, eğitimimi tamamladığımda r10'a bir teşekkür hediyesini unutmam ama

    Şimdi ben resim upload ederken şu kodları kullanıyorum

    $sayi1 = substr(md5(uniqid(rand())), 0,10); 
    $dosya = $_FILES['dup']['tmp_name']; 
    $isim2 = $_FILES['dup']['name'];  
    $isim = tr_converter($isim2);
    
    
    $hedef = "resimler"; 
    $son = $sayi1.'_'.substr($isim,-5);
    $dyukle = copy($dosya,$hedef.'/'.$son);
    $resim = 'resimler/'.$son;
    Daha sonrada $resim den gelen bilgiyi direk veritabanına yazdırıyorum.
    Gerçekten çok araştırdım birçok makalede buldum ama hep upuzun karışık kodlar verilip bırakılmış, bizim gibi yeni başlayan bunu nasıl entegre edeceğini bile bilmiyo haliyle.

    Kısaca Sorum;
    Ben bu fonksiyonlarla resimin bir tanede küçük kopyasını oluşturup upload edip bir de veritabanına yazmak üzere "http://site.com/resimler/kucukresim.jpg" gibi resimin adresini alarak veritabanına nasıl yazdırırım?
  • 09-08-2010, 17:20:42
    #2
    http://www.verot.net/php_class_upload.htm

    Bu sınıfı kullanın..
  • 09-08-2010, 19:25:52
    #3
    teşekkürler Aykut ama yine inceledim hiçbişey anlamadım, kısaca kodları yok mu bende anlasam hazıra konmasan sürekli, çünkü benim kullandığım upload yöntemi zaten karmaşık yada aşırı özelleştirilmiş değil.
  • 09-08-2010, 21:57:57
    #4
    THR
    Üyeliği durduruldu
    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
  • 10-08-2010, 14:09:50
    #5
    Saol THR bu işimi gördü okuyarak anladım da az çok