I have a form that uploads multiple images and that works just as I need it to. But I cant seem to get the description to add to the database. I just get [0] [1] and so on.
Here is my form.
echo “<form method=”post” enctype=”multipart/form-data” action=”manageimage.php?view=addpictures&userId=$userId&upload=files”>”;
$i=0;
while ($i < $_REQUEST[howmany] && $i < 5) {
echo “<input type=”hidden” name=”MAX_FILE_SIZE” value=”4194304″>
Image: <input type=”file” name=”userimage[]”><br>
<input type=”hidden” name=”imagemax” size=”4″ value=”168″>
Description: <input type=”text” name=”description$i” size=”24″><br><br>”;
$i++;
}
echo “<input type=”hidden” value=”$i” name=”uploads”>”;
echo “<input type=”submit” value=”Upload Images”></form>”;
Here is my upload and database script:
$i=0;
while ($i < $_REQUEST[uploads]) {
/////////////CREATE A THUMBNAIL FOR VIEWING
if ($_FILES[‘userimage’][‘type’][$i]==”image/pjpeg”) {
$thesize = $_REQUEST[imagemax];
$newWidth = $thesize;
$newHeight = $thesize;
$srcImage = ImageCreateFromJPEG($_FILES[‘userimage’][‘tmp_name’][$i]);
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
if($srcWidth < $srcHeight)
{
$destWidth = $newWidth * $srcWidth/$srcHeight;
$destHeight = $newHeight;
}
else
{
$destWidth = $newWidth;
$destHeight = $newHeight * $srcHeight/$srcWidth;
}
$destImage = imagecreatetruecolor($destWidth, $destHeight);
ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
ImageJPEG($destImage, “/home/mattdudley/momadddidley.com/htdocs/BLOG/imageuploads/RESIZED”.basename($_FILES[‘userimage’][‘name’][$i]));
ImageDestroy($srcImage);
ImageDestroy($destImage);
} else { echo “There was an error while uploading your image!”;
include(‘footer.inc’);
exit;}
/////////IMAGE FILES AND TYPE
$thefile=$_FILES[‘userimage’][‘name’][$i];
$resized=”RESIZED$thefile”;
$type=”image”;
//////////DATE
$month = date(“F”);
$day = date(“d”);
$year = date(“Y”);
$thedate=”$month $day, $year”;
///////////TIME
$hour = date(“h”);
$min = date(“i”);
$apm = date(“a”);
$thetime=”$hour:$min $apm”;
///////////////////ADD IMAGES TO THE DATABASE
$addimages=”INSERT INTO imagesTable set
imageFile=’$thefile’,
resizedimageFile=’$resized’,
description=’$_REQUEST[description][$i]’,
uploaddate=’$thedate’,
uploadtime=’$thetime’,
userId=’$userId’,
imageType=’$type'”;
$adddoit=mysql_query($addimages);
echo mysql_error();
$i++;
}
I was thinking I should change the field name to description[] rather than description$i. But that just produced something else. I brain has been getting squeezed over this for a while. Any help or suggestions would be sweet. Thanks
[url]www.momadddidley.com