I'm trying to write a script where users can upload as many as 12 images to my server. The end result of this will be a very simple gallery. I have run into a problem. I am storing the information in an array, but whenever all the upload forms are not used, information in still stored in the array. Is there a way to tell the array to disregard the fields that are not filled out?? Perhaps some code will make this more clear:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="multipleupload.php" method="post" enctype="multipart/form-data">
<input name="test[]" type="file" id="test[]">
<input name="test[]" type="file" id="test[]">
<input name="test[]" type="file" id="test[]">
<input type="submit" value="Upload!">
</form>
</body>
</html>
<?
require 'dbcon.php';
$images=serialize($_FILES['test']);
$count=count($_FILES['test']['name']);
$i=0;
echo " This is the $count";
// ==============
// Configuration
// ==============
$allowed_ext = "jpg"; // These are the allowed extensions of the files that are uploaded
$max_size = "50000"; // 50000 is the same as 50kb
$max_height = "600"; // This is in pixels
$max_width = "900"; // This is in pixels
$uploaddir = "/home/atlpartylife/atlpartylife.com/test/uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777!
while($i <= $count) {
// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES['test']['tmp_name'][$i]);
if($width > $max_width || $height > $max_height)
{
print "File height and/or width are too big!";
exit;
}
}
// ==============
// Upload Part
// ==============
if(is_uploaded_file($_FILES['test']['tmp_name'][$i]))
{
move_uploaded_file($_FILES['test']['tmp_name'][$i],$uploaddir.'/'.$_FILES['test']['name'][$i]);
}
$i++;
} //ends while loop
// Adds records to database
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die ("Unable to connect to database");
$query = "INSERT INTO stuff SET images='$images'";
mysql_query($query);
?>
O i almost forgot i am storing the array in a database so i can pull the file name out to use later.. Any help would be appreciated.