且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用一个输入字段上传多个图像

更新时间:2022-10-22 20:25:26

您可能正在寻找像 uploadify swfupload plupload


i have created a photography website with an admin page that uploads photos to different categories in a mysql table. This much works, but i can only upload one file at a time and i'd like to be able to select multiple images.

Here's 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's the php for parsing the form

if (isset($_POST['submit'])) {

$category = mysql_real_escape_string($_POST['category']);
// Add this product into the database now
$sql = mysql_query("INSERT INTO images (category, date_added) 
    VALUES('$category',now())") or die (mysql_error());


 $pid = mysql_insert_id();
// Place image in the folder 
$newname = "$pid.jpg";
move_uploaded_file( $_FILES['fileField']['tmp_name'], "../photos/$newname");
header("location: thumbnail_generator.php"); 
exit();
}

I looked into the html5 file input method, 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 can't figure out how to implement this into my php. Any help would be much appreciated.

You are probably looking for something like uploadify or swfupload or plupload.