• 27-01-2010, 15:33:49
    #1
    alttaki kodu kullanarak my_field[] şeklinde çoklu resim kayıt edebiliyorum.
    Diyelim 4 tane input my_field[] olsun 2 sinde resim seçeyim veri tabanına 2 dolu 2 de boş kayıt yapıyor neden olabilir?

    $sql = mysql_query("INSERT INTO resimler (isim,id) VALUES ('".$handle->file_dst_name."','$id')");

    kısmı en alta koyuncada 1 ini kayıt ediyor.

     <?php
    
    
    
        // ---------- MULTIPLE UPLOADS ----------
    
        // as it is multiple uploads, we will parse the $_FILES array to reorganize it into $files
        $files = array();
        foreach ($_FILES['my_field'] as $k => $l) {
            foreach ($l as $i => $v) {
                if (!array_key_exists($i, $files))
                    $files[$i] = array();
                $files[$i][$k] = $v;
            }
        }
    
        // now we can loop through $files, and feed each element to the class
        foreach ($files as $file) {
    
            // we instanciate the class for each element of $file
            $handle = new Upload($file);
    
            // then we check if the file has been uploaded properly
            // in its *temporary* location in the server (often, it is /tmp)
            if ($handle->uploaded) {
    
    	$handle->image_resize = true;
    	$handle->image_x = 565;
    	$handle->image_ratio_y = true;
    	$handle->image_watermark = 'tkntxt.png';
    	$handle->image_watermark_x = 365;
    	$handle->image_watermark_y = 348;
    	$handle->file_max_size = '10240000'; // 1KB
    
    
    
                // now, we start the upload 'process'. That is, to copy the uploaded file
                // from its temporary location to the wanted location
                // It could be something like $handle->Process('/home/www/my_uploads/');
                $handle->Process($dir_dest);
    
                // we check if everything went OK
                if ($handle->processed) {
                    // everything was fine !
                    echo '<fieldset>';
                    echo '  <legend>Resim Eklendi</legend>';
                    echo '  <p>' . round(filesize($handle->file_dst_pathname)/256000)/4 . 'KB</p>';
                    echo '  Eklenen Resim: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
                    echo '</fieldset>';
                    
                 
                } else {
                    // one error occured
                    echo '<fieldset>';
                    echo '  <legend>Resim Eklenmedi</legend>';
                    echo '  Error: ' . $handle->error . '';
                    echo '</fieldset>';
                }
    
            } else {
                // if we're here, the upload file failed for some reasons
                // i.e. the server didn't receive the file
                echo '<fieldset>';
                echo '  <legend>Resim Eklenmedi</legend>';
                echo '  Error: ' . $handle->error . '';
                echo '</fieldset>';
            } 
                
    $sql = mysql_query("INSERT INTO resimler (isim,id) VALUES ('".$handle->file_dst_name."','$id')"); 
    
       
        }
    
    
    ?>
  • 27-01-2010, 16:07:32
    #2
    Kimlik doğrulama veya yönetimden onay bekliyor.
    $url = $_POST['my_fields'];
    if($url!="")
    {
    $sql = mysql_query("INSERT INTO galeriler_foto (foto_url,galeri_id) VALUES ('$url','$_galeri_id')");
    }


    bu şekilde mantık geliştirerek inputtan gelen verinin boş veya doluluk kontrolunu yaparak kayıt yaptırabilirsiniz. Sadece dolu olan inputları eklerseniz bu şekilde.
  • 27-01-2010, 16:24:24
    #3
    saolasın