Here is an example where I give a form to upload upto 12 fotos.
1) the form tag must have the following property: enctype="multipart/form-data", as well as using the post method. So the full tag of the upload form would look something akin to:
<form method="post" action="upload_script.php" enctype="multipart/form-data">
And each file upload field is like:
<input type="file" name="fotoN"> (where N is 1-12)
I also allow a title for each photo after the upload field:
<select name="foto_textN">
<option>foo</option>
...
<option>bar</option>
</select>
My table structure is as follows:
CREATE TABLE imagenes (
imagen_num int(10) unsigned NOT NULL auto_increment,
prop_num mediumint(8) unsigned NOT NULL default '0',
titulo tinyint(3) unsigned NOT NULL default '0',
type varchar(12) NOT NULL default '',
width smallint(5) unsigned NOT NULL default '0',
height smallint(5) unsigned NOT NULL default '0',
file blob NOT NULL,
PRIMARY KEY (imagen_num)
)
2) The upload_script.php could handle the uploaded file in the following manner:
/ Explicitly assign each Photo varible into its corresponding array "type" /
$foto = array($foto0, $foto1, $foto2, $foto3, $foto4, $foto5, $foto6, $foto7, $foto8, $foto9, $foto10, $foto11);
$foto_name = array($foto0_name, $foto1_name, $foto2_name, $foto3_name, $foto4_name, $foto5_name, $foto6_name, $foto7_name, $foto8_name, $foto9_name, $foto10_name, $foto11_name);
$foto_size = array($foto0_size, $foto1_size, $foto2_size, $foto3_size, $foto4_size, $foto5_size, $foto6_size, $foto7_size, $foto8_size, $foto9_size, $foto10_size, $foto11_size);
$foto_type = array($foto0_type, $foto1_type, $foto2_type, $foto3_type, $foto4_type, $foto5_type, $foto6_type, $foto7_type, $foto8_type, $foto9_type, $foto10_type, $foto11_type);
$foto_text = array($foto_text0, $foto_text1, $foto_text2, $foto_text3, $foto_text4, $foto_text5, $foto_text6, $foto_text7, $foto_text8, $foto_text9, $foto_text10, $foto_text11);
/ Initialize the Photo count /
$foto_quant = 0;
$foto_upload = 0;
/ Count the photos successfully uploaded and of correct format - Here I check to see if each file has the specifications I require. File size is available for all file types and then I can check dimensions because they are images /
$bad_image_num=""; // This is used for an error message to the user
for($j=0;$j<12;$j++){
if(($foto[$j]!="none")&&($foto_size[$j]!=0)&&($foto_size[$j]<=20480)){
$image_count=$j+1;
$size = GetImageSize($foto[$j]);
if((($size[0]<289)&&($size[1]<289)) && (($foto_type[$j]=="image/gif")||(($foto_type[$j]=="image/jpeg")||($foto_type[$j]=="image/pjpeg"))||(($foto_type[$j]=="image/png")||($foto_type[$j]=="image/x-png")))){
$foto_quant++;
}else{
if($bad_image_num==""){
$bad_image_num.="$image_count";
}else{
$bad_image_num.=", $image_count";
}
}
}
}
/* Load each photo into the database */
for($i=0;$i<$foto_quant;$i++){
$size = GetImageSize($foto[$i]);
If(($foto[$i] != "none")&&($foto_size[$i]<20001)&&(($size[0]<289)&&($size[1]<289))&&($foto_type[$i]=="image/gif"||($foto_type[$i]=="image/jpeg"||$foto_type[$i]=="image/pjpeg")||($foto_type[$i]=="image/png"||$foto_type[$i]=="image/x-png"))){
$mysqlPicture = addslashes(fread(fopen($foto[$i], "r"), $foto_size[$i]));
$foto_query = "INSERT into imagenes (prop_num, titulo, type, width, height, file) values ($prop_num, '$foto_text[$i]','$foto_type[$i]',$size[0],$size[1],'$mysqlPicture')";
$foto_success = mysql_query($foto_query) or die("Error 304: No se pudo insertar la imagen nรบmero $i.<p>$error");
unlink($foto[$i]);
$foto_upload++;
}else{
$g=$i+1; // Again, used for error reporting to the end user
}
}
Well, that's it. I hope it helps.