通过ajax将表单文件发送到php
我想通过ajax将文件发送到php,我有下面的代码,但当我运行它时,它会显示未定义的索引:thefile 有什么问题? HTML 及表格:通过ajax将表单文件发送到php,php,html,ajax,Php,Html,Ajax,我想通过ajax将文件发送到php,我有下面的代码,但当我运行它时,它会显示未定义的索引:thefile 有什么问题? HTML 及表格: <form action="#" > <input type="file" name="thefile" id="thefile"/> <input type="button" name="Send" value="send" onclick="postData('upLoad.php');"/> </form&
<form action="#" >
<input type="file" name="thefile" id="thefile"/>
<input type="button" name="Send" value="send" onclick="postData('upLoad.php');"/> </form>
这适用于有多个文件的情况,但也适用于一个文件:
var formData = new FormData();
jQuery.each($('#thefile')[0].files, function(i, file) {
formData.append('thefile-'+i, file);
});
第一个文件现在可以在以下位置找到:
$_FILES['thefile-0']
还要确保设置内容类型。
$\u文件
必须为空。我在任何地方都看不到multipart/form data
。@PLB您能给我解释一下吗?添加xmlHttp.setRequestHeader(“内容类型”,“multipart/form data”)
在onreadystatechange之前,但它没有解决问题
var formData = new FormData();
jQuery.each($('#thefile')[0].files, function(i, file) {
formData.append('thefile-'+i, file);
});
$_FILES['thefile-0']