Hello.
I have an image system kinda working, when it uploads however it is uoloading calling all the images ARRAY.gif or ARRAY.jpg
Can you see what I should do that it correctly list the images name. The code is two parts. The preupload form page NEXT To The photos.php page where you see your image...
Thanks kindly any help is appreciated!
------------------------------
This is the preupload.php page
<?php
include 'db.php';
// initialization
$photo_upload_fields = "";
$counter = 1;
// default number of fields
$number_of_fields = 4;
// If you want more fields, then the call to this page should be like,
// preuploads.php?number_of_fields=20
if( $_GET['number_of_fields'] )
$number_of_fields = (int)($_GET['number_of_fields']);
if( $_GET['category_name'] )
$category_name =($_GET['category_name']);
if( $_GET['name'] )
$name =($_GET['name']);
// 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[5]</option>\n
__HTML_END;
}
mysql_free_result( $result );
// Lets build the Photo Uploading fields
while( $counter <= $number_of_fields )
{
$photo_upload_fields.=<<<__HTML_END
<tr>
<td>
Photo {$counter}:
<input name='photo_filename[]' type='file' />
</td>
</tr>
<tr>
<td>
Caption:
<textarea name='name[]' cols='80' rows='1'></textarea>
</td>
</tr>
__HTML_END;
$counter++;
}
// Final Output
echo <<<__HTML_END
<html>
<head>
<title>Lets upload Photos</title>
</head>
<body>
<form enctype='multipart/form-data' action='photos.php' method='post' name='upload_form'>
<table width='90%' border='0' align='center' style='width: 90%;'>
<tr>
<td>
Select Category
<select name='category'>
$photo_category
<option>Woman
<option>Man
</select>
</td>
</tr>
<tr>
<td>
<p> </p>
</td>
</tr>
<!-Insert the photo fields here -->
$photo_upload_fields
<tr>
<td>
<input type='submit' name='submit' value='Add Photos' />
</td>
</tr>
</table>
</form>
</body>
</html>
__HTML_END;
?>
------------------------------------------------------------------------
Next to the photos.php page where the images are seen
<?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 preupload.php
$photos_uploaded = $_FILES['photo_filename'];
// Fetch the photo caption array
$name = $_POST['name'];
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)."', name='".($name)."' WHERE
email_address='".($email_address)."'" );
$filetype = $photos_uploaded['type'][$counter];
$extention = $known_photo_types[$filetype];
$filename = $name.".".$extention;
$sql_update = mysql_query("UPDATE gallery_photos SET
photo_filename='".($filename)."', name='".($name)."' WHERE
email_address='".($email_address)."'" );
$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."/".$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."/".$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."/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;
?>
</p>
</table>
</body>
</html>