I created a photo website with an admin page that uploads photos into different categories in the mysql table. This works a lot, but I can only upload one file at a time, and I would like to be able to select multiple images.
Here is the form
<form action="index.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
<select name="category" id="category">
<option value="Nature">Nature</option>
<option value="People">People</option>
<option value="Abstract">Abstract</option>
</select>
<input type="file" name="fileField" id="fileField" />
<input type="submit" name="submit" id="submit" value="Add Images" />
</form>
And here is php for parsing the form
if (isset($_POST['submit'])) {
$category = mysql_real_escape_string($_POST['category']);
$sql = mysql_query("INSERT INTO images (category, date_added)
VALUES('$category',now())") or die (mysql_error());
$pid = mysql_insert_id();
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../photos/$newname");
header("location: thumbnail_generator.php");
exit();
}
I looked at the input method of the html5 file, and as far as I can tell, I can change the input as folllows:
<input type="file" name="fileField[]" id="fileField" multiple="multiple"/>
This allows me to select multiple files on the site, but I cannot figure out how to implement this in my php. Any help would be greatly appreciated.
source
share