images php coding issues or problems here.
Moderators: macek, egami, gesf
by dolphin2005 » Wed Apr 06, 2005 8:30 am
I have the following code which is meant to take the input from an upload form and create thumbnails and then store the information in a database but the code seems to store the word array in the photo_title field rather than the text that is inputed on the form. can any one help me with this problem.
- Code: Select all
<?php
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 maths pro array
$photo_mathsprogram = $_POST['photo_mathsprogram'];
$photo_title = $_POST['photo_title'];
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_title ,photo_mathsprogram, `photo_category`) VALUES('0','$photo_title','".addslashes($photo_mathsprogram[$counter])."', '".addslashes($_POST['category'])."')" );
$new_id = mysql_insert_id();
$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 = 600;
$thumbnail_height = (int)(600* $size[1] / $size[0]);
}
else
{
$thumbnail_width = (int)(600 * $size[0] / $size[1]);
$thumbnail_height = 600;
}
// 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."/".$filename );
if($source_handle)
{
// Let's create an blank image for the thumbnail
$destination_handle = ImageCreateTrueColor ( $thumbnail_width, $thumbnail_height );
// Now we resize it
ImageCopyResampled( $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."/tb_".$filename );
ImageDestroy($destination_handle );
//
$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;
?>
-
dolphin2005
- New php-forum User

-
- Posts: 2
- Joined: Wed Apr 06, 2005 8:26 am
by ruturajv » Wed Apr 06, 2005 8:09 pm
are u using multiple uploads where there is
<input name='photo_title[]' ... >
or try
- Code: Select all
print_r($_POST['photo_title'])
-

ruturajv
- php-forum Super User

-
- Posts: 1280
- Joined: Sat Mar 22, 2003 9:42 am
- Location: Mumbai, India
-
Return to PHP coding => Images
Who is online
Users browsing this forum: No registered users and 1 guest