我有这个脚本javascript:
function submitCID(){
var file_data = $('#cidLoader').prop('files')[0];
var form_data = new FormData();
form_data.append('cidLoader', file_data);
$.ajax({
url: "/uploadCid.php",
dataType: 'text',
cache: false,
contentType: false,
processData: false,
data: form_data,
success: function(){
alert("ok");
},
error: function(jqXHR, textStatus, errorThrown){
alert(jqXHR.responseText);
}
});
}
上传.cid文件(如xml)。
PHP代码是:
<?php
$filename = $_FILES["cidLoader"]["name"];
echo "Upload: " . $_FILES["cidLoader"]["name"] . "<br>";
echo "Type: " . $_FILES["cidLoader"]["type"] . "<br>";
echo "Size: " . ($_FILES["cidLoader"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["cidLoader"]["tmp_name"] . "<br>";
?>
HTML表单是这样的:
<form method="POST" id="fileInfo" enctype="multipart/form-data">
<input id="cidLoader" name="cidLoader" type="file" accept=".cid,.CID" />
</form>
不幸的是我收到错误:未定义的索引:cidLoader
有什么问题?