Hello ,

If you know the answer please simplify it for me. I am so discouraged trying to figure this out. I'll be very grateful, Thanks ahead a time!

When I insert my (2) selected photos in my photo form , they show two pictures but it repeats only (1) of the pictures. it shows up double.

Next it goes to the directory as one image name and type.

Next in the database I have photo1 and photo2 it logs in photo1 and photo2 the same image though,

but in name1 and name2 it logs the name correctly but no type!

For the life of me I cannot get the pictures to show up as the two seperate photos I am inserting, and log in the database as photo1 and photo2 as two seperate photos... They log photo1 and photo2 as the same name and type... CAN you HELP!

Easily I select cat.gif and dog.gif on display only cat.gif displays twice ...

In the directory it logs only once cat.gif ...

In the database it logs repeated cat.gif in photo1 and photo2 ....

In the database under name1 it is logging cat and in name2 it is logging dog correctly but no type!

How can I write it correctly that two photos are being selected and not just one... Here is my code:

____________________
THIS IS THE PHOTO_FORM

<?php
include 'db.php';

// initialization
  $photo_upload;
  $counter = 1;

if( $_GET['number_of_fields'] )
$number_of_fields = (int)($_GET['number_of_fields']);

// Firstly Lets build the Category List
$result = mysql_query( "SELECT category_id,category_name FROM gallery_category" );
while( $row = mysql_fetch_array( $result ) )
{
$photo_category_list .=<<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
mysql_free_result( $result ); 

// Lets build the Photo Uploading fields
while( $counter <= $number_of_fields )
{
$photos_upload;

__HTML_END;
$counter++;
}
// Final Output
echo <<<__HTML_END


<!-Insert the photo fields here -->
$photo_upload

<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<table>
<tr>
<td> 
<form name="photo_filename" action="photos.php" method="post" enctype="multipart/form-data">
<p><b> 
Photo: 
<input name="photo_filename[]" type="file">
Caption: <textarea name='name' cols='20' rows='1'></textarea></p>
<br>

<p>Photo:
<input name="photo_filename[]" type="file">
Caption: <textarea name='name2' cols='20' rows='1'></textarea></p>


<tr>
<td>
<input type='submit' name='submit' value='Add Photos' />
</td>
</tr>
</table>
</form>
</body>
</html>
__HTML_END;
?>

_______________
THIS IS THE DISPLAY

<?php
  include 'db.php';


  // initialization
  $result_final = "";
  $counter = 0;
  // List of our known photo types
  $known_photo_types = array( 
            'image/pjpeg' => 'jpg',
            'image/jpeg' => 'jpg',
            'image/gif' => 'gif',
            'image/bmp' => 'bmp',
            'image/x-png' => 'png'
          );

  // GD Function List
  $gd_function_suffix = array( 
            'image/pjpeg' => 'JPEG',
            'image/jpeg' => 'JPEG',
            'image/gif' => 'GIF',
            'image/bmp' => 'WBMP',
            'image/x-png' => 'PNG'
          );

  //ignore anything starting with a period.
  if(substr($filename, 0, 1)!='.')

// Fetch the photo array sent by preuploads.php
   $photos_uploaded = $_FILES['photo_filename'];


  // Fetch the photo caption array
   $_POST['name'];
   $_POST['name2'];

   while( $counter <= count($photos_uploaded) )
  {
   if($photos_uploaded['size'][$counter] > 0)
    {
     if(!array_key_exists($photos_uploaded['type'][$counter], $known_photo_types))
      {      
       $result_final .= "File ".($counter+1)." is not a photo<br />";

       }else{
        $sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."', 
        name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );
        $filetype = $photos_uploaded['type'][$counter];
        $extention = $known_photo_types[$filetype];
        $filename = $name.".".$extention;         



        $sql_update = mysql_query("UPDATE gallery_photos SET photo_filename='".($filename)."', photo2_filename='".($filename)."', 
        name='".($name)."', name2='".($name2)."' WHERE email_address='".($email_address)."' AND password='".($password)."'" );

        $sql_check_num = mysql_num_rows($sql_check); 
        if($sql_check_num == 0){ 

          echo ("");
        } else {
          echo ("");
        }

        // Store the orignal file
        copy($photos_uploaded['tmp_name'][$counter], $images_dir."/$name_".$filename );

        // Let's get the Thumbnail size
        $size = GetImageSize( $images_dir."/".$filename );
        if($size[0] > $size[1])
        {
          $thumbnail_width = 100;
          $thumbnail_height = (int)(100 * $size[1] / $size[0]);
        }
        else
        {
          $thumbnail_width = (int)(100 * $size[0] / $size[1]);
          $thumbnail_height = 100;
        }

        // Build Thumbnail with GD 1.x.x, you can use the other described methods too
        $function_suffix = $gd_function_suffix[$filetype];
        $function_to_read = "ImageCreateFrom".$function_suffix;
        $function_to_write = "Image".$function_suffix;

        // Read the source file
        $source_handle = $function_to_read ( $images_dir."/$name_".$filename );

        if($source_handle)
        {
          // Let's create an blank image for the thumbnail
               $destination_handle = ImageCreate ( $thumbnail_width, $thumbnail_height );

          // Now we resize it
        ImageCopyResized( $destination_handle, $source_handle, 0, 0, 0, 0, $thumbnail_width,  
        $thumbnail_height, $size[0], $size[1] );
        }

        // Let's save the thumbnail
        $function_to_write( $destination_handle, $images_dir."/$name_".$filename );
        ImageDestroy($destination_handle );
        //

        $result_final .= "<img src='".$images_dir. "/$name_".$filename."' /> File ".($counter+1)." 

Added<br />";
      }
    }
  $counter++;
  }

  // Print Result
echo <<<__HTML_END

<html>
<head>
  <title>Photos uploaded</title>
</head>
<body>
     $result_final
</body>
</html>

__HTML_END;
?>
</p>


 </table>
 </body>
</html>

P.S IF I TRY TO ADD photo2_filename it doesn't work!
Your help will be really appreciated, Thanks Puddin

Recommended Answers

All 2 Replies

I haven't finish all your code but I spot something that is not suitable in HTML - In the PHOTO_FORM, you have photo_filename[] as you input name of the file. As HTML is not like php, it will not take your file data into an array. You may want to change it to photo_filename1 and photo_filename2 for the second image.

Then in your upload script, use $_POST and $_POST to retrive it. If you have to upload many images at once, you can use For loop to remove the need of repeating scripts.

Post your finding here again if it still not working.

I haven't finish all your code but I spot something that is not suitable in HTML - In the PHOTO_FORM, you have photo_filename[] as you input name of the file.

No!!!!
You can use that in HTML. photo_filename[] is perfectly legal in HTML. It will store all the selected options into an array. There is nothing wrong with that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.