我将多个上传文件保存到数据库时遇到问题。我使用html 5拖放多个上传文件。例如,我想在1个表中保存2个图像但不同的行。所以,这是我简单的结构表数据库和web。
表数据库
name, 'int', '25'.
image1, 'var', '100'.
image2, 'var', '100'.
的index.php
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="multiupload.js"></script>
<script type="text/javascript">
var config = {
// Valid file formats
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif",
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles", // Upload Area ID
uploadUrl: "upload.php" // Server side file url
}
//Initiate file uploader.
$(document).ready(function()
{
initMultiUploader(config);
});
</script>
</head>
<body>
<div id="dragAndDropFiles" class="uploadArea">
<h1>Drop Images Here</h1>
</div>
<form name="demoFiler" id="demoFiler" enctype="multipart/form-data">
<input type="file" name="multiUpload" id="multiUpload" multiple />
<input type="submit" name="submitHandler" id="submitHandler" value="Upload" />
</form>
<div class="progressBar">
<div class="status"></div>
</div>
</body>
</html>
upload.php的
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".$_FILES['file']['name']))
{
echo($_POST['index']); // to validate
}
exit;
}
?>
那么,我必须做些什么才能修改upload.php脚本?谢谢你的建议..
答案 0 :(得分:0)
您可以像这样使用表单:
首先,您需要将表单选择更改为:name="multiUpload[]"
$arr = $_GET['multiUpload'];
foreach($arr as $option) {
echo $option."<br>"; //Do whatever you want.
}