使用一个输入字段上传多个图像 [英] Uploading multiple images with one input field
问题描述
我创建了一个具有管理页面的摄影网站,可以将照片上传到不同类别的mysql表格中。这很有效,但我只能一次上传一个文件,我希望能够选择多个图像。
下面是表单
< form action =index.phpenctype =multipart / form-dataname =myFormid =myFormmethod = 后 >
< option value =自然>自然< / option>
< option value =People>人物< / option>
< option value =摘要>摘要< / option>
< / select>
< input type =filename =fileFieldid =fileField/>
< input type =submitname =submitid =submitvalue =Add Images/>
< / form>
这里是解析表单的php
< ($ _ POST ['submit'])){
$ category = mysql_real_escape_string($ _ POST ['category']); pre> if
//将此产品添加到数据库中
$ 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();
}
我查看了html5文件的输入法,据我所知,我可以改变输入作为folllows:
< input type =filename =fileField []id = fileFieldmultiple =multiple/>
这使我可以在网站上选择多个文件,但我无法弄清楚如何执行这到我的PHP。任何帮助将不胜感激。
您可能正在寻找像 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.
这篇关于使用一个输入字段上传多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!