Jump to content

Help with image uploading!


oobs

Recommended Posts

okay so im making a image uploading form.

 

this is the php file that actually uploads the file that was previously defined on another page.

 

but when i click upload it will only save the file as 0.jpg and if i upload another (different) file it will just overwrite 0.jpg. how do i make it auto-increment correctly!?

 

	include("config.inc.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'
				);

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

// Fetch the photo caption array
$photo_caption = $_POST['photo_caption'];

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
		{
			mysql_query( "INSERT INTO gallery_photos(`photo_filename`, `photo_caption`, `photo_category`) VALUES('0', '".addslashes($photo_caption[$counter])."', '".addslashes($_POST['category'])."')" );
			$new_id = $counter;
			$filetype = $photos_uploaded['type'][$counter];
			$extention = $known_photo_types[$filetype];
			$filename = $new_id.".".$extention;

			mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" );

			// Store the orignal file
			copy($photos_uploaded['tmp_name'][$counter], $images_dir."/".$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;
			}



			$result_final .= "<img src='".$images_dir. "/tb_".$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;

 

thankyou so much in advance!

Link to comment
https://forums.phpfreaks.com/topic/139656-help-with-image-uploading/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.