• 09-03-2014, 15:10:25
    #1
    Arkadaşlar resim yüklerken bir sıkıntı yaşıyorum

    Veritabanınmda bir tabloya Eğer Gelen Resimde birşey yoksa Otomatik deger ata diyorum ama bu kodları kullanırken hep dolu değer yolluyor yanı null olmuyor bunu nasıl düzeltebiliriz acaba




    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) 
    {
    
    include_once('class.upload.php');
     
    $upload = new upload($_FILES['resim']);
     
    if ($upload->uploaded)
    {
    	$upload->file_auto_rename = true;
    	$upload->allowed = array('image/*');
    	$upload->file_new_name_body = uniqid(true);
    	$upload->image_resize = true;
    	$upload->image_x = 1280;
    	$upload->image_y = 716;
    	$upload->process('../images/');
    	$adi =$upload->file_dst_name;
    
    }
    
    $insertSQL = sprintf("INSERT INTO slider (resim, resimyazi, resimlink, resimbutonyazi, resimbutonsekli) VALUES (%s, %s, %s, %s, %s)", 
      GetSQLValueString($adi, "text"), 
      GetSQLValueString($_POST['resimyazi'], "text"), 
      GetSQLValueString($_POST['resimlink'], "text"),
      GetSQLValueString($_POST['resimbutonyazi'], "text"),
      GetSQLValueString($_POST['resimbutonsekli'], "text"));
  • 09-03-2014, 19:26:49
    #2
    Kimlik doğrulama veya yönetimden onay bekliyor.
    @TuncerMehmet; PMA (phpMyAdmin) aracılığıyla tablonuzun yapısın ekran görüntüsü alıp konuya ekler misiniz?
  • 09-03-2014, 19:33:25
    #3
    Buyurun hocam
  • 09-03-2014, 20:12:21
    #4
    @TuncerMehmet; şu şekilde deneyebilir misin?

    if((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
    {
    	include_once("class.upload.php");
    	
    	$upload = new upload($_FILES["resim"]);
    	
    	if($upload->uploaded)
    	{
    		$upload->file_auto_rename = true;
    		$upload->allowed = array("image/*");
    		$upload->file_new_name_body = uniqid(true);
    		$upload->image_resize = true;
    		$upload->image_x = 1280;
    		$upload->image_y = 716;
    		$upload->process("../images/");
    		$adi = $upload->file_dst_name;
    	}
    	$insertSQL = sprintf(
    		"INSERT INTO slider (resim, resimyazi, resimlink, resimbutonyazi, resimbutonsekli) VALUES (%s, %s, %s, %s, %s)", 
    		GetSQLValueString($adi, "text"), 
    		GetSQLValueString(isset($_POST["resimyazi"]) ? $_POST["resimyazi"] : "NULL", "text"), 
    		GetSQLValueString(isset($_POST["resimlink"]) ? $_POST["resimlink"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonyazi"]) ? $_POST["resimbutonyazi"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonsekli"]) ? $_POST["resimbutonsekli"] : "NULL", "text")
    	);
  • 09-03-2014, 20:15:11
    #5
    Mümkün mertebe class kullanmamaya çalışan biri olarak kendi kullandığım upload dosyamdaki kodları sadeleştirip aşağıya ekliyorum. Gerekli yerleri düzenlerseniz rahatlıkla kullanabilirsiniz.

    Aşağıdaki kodların tamamını eğer resim geldiyse şeklinde bir if yapısı içine şu şekilde alabilirsiniz; (tüm kodlarda resim inputu name'i "resim" farzedilmiştir)
    if( !empty($_FILES['resim']["tmp_name"]) ){ aşağıdaki tüm kodlar buraya }
    else{ resim dosyası gönderilmediyse yapılacak işlemler }
    $kaynak		= @$_FILES['resim']["tmp_name"];
    $resim		= @$_FILES['resim']["name"];
    $tip			= @$_FILES['resim']["type"];
    $boyut 		= round(@$_FILES['resim']['size'] / 1024);
    
    if($tip != "image/jpeg" || $tip != "image/png"){echo "bu geçerli bir resim dosyası değil"; exit;}
    $yol			= "resmin yükleneceği dizin yolu";
    $uzanti		= strtolower(substr($resim, -4)); if($uzanti == "jpeg"){ $uzanti=".jpg"; }
    if( $uzanti != ".jpg" || $uzanti != ".png"){echo "geçerli bir resim dosyası değil"; exit;}
    $resim 		= "resme_isim_ver".$uzanti;
    if( $boyut > 1024 ){ echo "resim boyutu en fazla 1mb olabilir"; exit;}
    
    $yukle = @move_uploaded_file($kaynak,$yol.$resim);
    if(!$yukle){ echo 'Resim yüklenirken bir hata oluştu'; exit;}
    Resim sunucuya yüklendi. Boyutlandıralım;

    $r_genislik=1280; /* resmin yeni eni (px) */
    $r_yukseklik=716; /* resmin yeni boyu (px) */
    list($gen, $yuk, $type) = getimagesize($yol.$resim);
    $enOran = $r_genislik / $gen;
    $boyOran = $r_yukseklik / $yuk;
    if($enOran > $boyOran){
    	$yEn = floor($gen * $enOran);
    	$yBoy = floor($yuk * $enOran);
    }else{
    	$yEn = floor($gen * $boyOran);
    	$yBoy = floor($yuk * $boyOran);
    }
    $fEn = floor(0 - (($yEn - $r_genislik) / 2));
    $fBoy = floor(0 - (($yBoy - $r_yukseklik) / 2));
    if( $uzanti == ".jpg" ){
    	$o_img = imagecreatefromjpeg($yol.$resim);
    	$g_img = imagecreatetruecolor($r_genislik, $r_yukseklik);
    	imagecopyresampled($g_img,$o_img,$fEn,$fBoy,0,0,$yEn,$yBoy,$gen,$yuk);
    	imagejpeg($g_img, $yol.$resim,100);
    	imagedestroy($o_img);
    	imagedestroy($g_img);
    }elseif( $uzanti == ".png" ){
    	$o_img = imagecreatefrompng($yol.$resim);
    	$g_img = imagecreatetruecolor($r_genislik, $r_yukseklik);
    	imagecopyresampled($g_img,$o_img,$fEn,$fBoy,0,0,$yEn,$yBoy,$gen,$yuk);
    	imagepng($g_img, $yol.$resim);
    	imagedestroy($o_img);
    	imagedestroy($g_img);
    }
  • 09-03-2014, 20:18:02
    #6
    saintx adlı üyeden alıntı: mesajı görüntüle
    @TuncerMehmet; şu şekilde deneyebilir misin?

    if((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
    {
    	include_once("class.upload.php");
    	
    	$upload = new upload($_FILES["resim"]);
    	
    	if($upload->uploaded)
    	{
    		$upload->file_auto_rename = true;
    		$upload->allowed = array("image/*");
    		$upload->file_new_name_body = uniqid(true);
    		$upload->image_resize = true;
    		$upload->image_x = 1280;
    		$upload->image_y = 716;
    		$upload->process("../images/");
    		$adi = $upload->file_dst_name;
    	}
    	$insertSQL = sprintf(
    		"INSERT INTO slider (resim, resimyazi, resimlink, resimbutonyazi, resimbutonsekli) VALUES (%s, %s, %s, %s, %s)", 
    		GetSQLValueString($adi, "text"), 
    		GetSQLValueString(isset($_POST["resimyazi"]) ? $_POST["resimyazi"] : "NULL", "text"), 
    		GetSQLValueString(isset($_POST["resimlink"]) ? $_POST["resimlink"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonyazi"]) ? $_POST["resimbutonyazi"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonsekli"]) ? $_POST["resimbutonsekli"] : "NULL", "text")
    	);



    GetSQLValueString($adi, "text"), Bu satırda hata veriyor hocam " Column 'resim' cannot be null " diyor
  • 09-03-2014, 20:21:17
    #7
    @dark_way; soru resize ile alakalı değil ki

    @TuncerMehmet; şu şekilde deneyebilir misiniz?

    <?php
    
    if((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1"))
    {
    	include_once("class.upload.php");
    	
    	$upload = new upload($_FILES["resim"]);
    	
    	if($upload->uploaded)
    	{
    		$upload->file_auto_rename = true;
    		$upload->allowed = array("image/*");
    		$upload->file_new_name_body = uniqid(true);
    		$upload->image_resize = true;
    		$upload->image_x = 1280;
    		$upload->image_y = 716;
    		$upload->process("../images/");
    		$adi = is_null($upload->file_dst_name) || empty($upload->file_dst_name) ? "resimyok.png" : $upload->file_dst_name;
    	}
    	$insertSQL = sprintf(
    		"INSERT INTO slider (resim, resimyazi, resimlink, resimbutonyazi, resimbutonsekli) VALUES (%s, %s, %s, %s, %s)", 
    		GetSQLValueString($adi, "text"),
    		GetSQLValueString(isset($_POST["resimyazi"]) ? $_POST["resimyazi"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimlink"]) ? $_POST["resimlink"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonyazi"]) ? $_POST["resimbutonyazi"] : "NULL", "text"),
    		GetSQLValueString(isset($_POST["resimbutonsekli"]) ? $_POST["resimbutonsekli"] : "NULL", "text")
    	);
  • 09-03-2014, 20:22:57
    #8
    @saintx; , biliyorum ya kaptırdım konunun başında belirttim asıl olayı ifle resim var mı yok mu bakçak işte

    edit; şu etiketleme işini yapamadım gitti he
  • 09-03-2014, 20:34:15
    #9
    hocam veritabanında resim bolumne null yaptım boş ekleye biliyorum ama değeri almiyor