表单:HTML
<form class="general_form" id="winner_form" >
//upload profile picture
<label for="profile_pic">Profile picture</label>
<input type="file" class="file" name="profile_pic" accept="image/*" required><br><br>
//upload multiple pictures
<label for="pictures">Select Multiple Pictures</label>
<input type="file" class="file" name="pictures[]" accept="image/*" multiple><br><br>
//submit
<button type="submit"> Submit</button>
</form>
表格:JS
$(document).ready(function() {
$(".general_form").submit(function(e) {
//grab all form data
var data = new FormData($('#winner_form')[0]);
e.preventDefault();
$.ajax({
url: 'upload.php',
type: 'POST',
datatype: "html",
data: data,
cache: false,
contentType: false,
processData: false,
success: function(data){
if(data.error)
alert("ERROR");
else
document.write(data);
},
error: function(data) {
alert("ERROR");
document.write(data);
}
});
e.preventDefault();
});
});
每次打印$ _REQUEST&amp; $ _FILES内容我上传的文件更改位置
$_REQUEST =
array(3) {
string(11) "images.jpeg"
["pictures"]=>
array(2) {
[0]=>
string(8) "pic1.png"
[1]=>
string(8) "pic2.png"
}
}
}
$_FILES =
array(0) {}
$_REQUEST =
array(2) {
["profile_pic"]=>
array(5) {
["name"]=>
string(11) "images.jpeg"
["type"]=> ..
["tmp_name"]=> ..
["error"]=> ..
["size"]=> ..
}
$_FILES =
["pictures"]=>
array(5) {
["name"]=>
array(2) {
[0]=>
string(8) "pic1.png"
[1]=>
string(8) "pic2.png"
}
["type"]=> ..
}
["tmp_name"]=> ..
}
["error"]=> ..
}
["size"]=> ..
}
}
}
非常感谢您的所有帮助