我想上传文件数据和变量,当我提交文件时它很顺利。但如果我附加变量,则什么也没发生。我看到的是文件数据。
HTML:
<form id="articleData">
<input type="hidden" name="id" value="123" readonly="readonly">
Upload article csv: <input name="articleCsv[]" type="file" /><br />
<input type="radio" name="item" value="add">Add new items<br>
<input type="radio" name="item" value="update">Update items
<input type="submit" value="Submit">
</form>
这是我的ajax请求:
$("form#articleData").submit(function(event){
//disable the default form submission
event.preventDefault();
var checked = $('input[name=item]:checked', '#articleData').val();
//grab all form data
var formData = new FormData($(this)[0]);
formData.append('updateOrAdd',checked);
$.ajax({
url: "/spares/admin/importArticleCsv",
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (returndata) {
alert(returndata);
}
});
return false;
});
我的php:
public function importArticleCsv(){
$output[] = array();
$response[] = "";
$this->load->model('admin/csv');
$url = $_FILES['articleCsv']['tmp_name'][0];
$updateOrAdd = $_FILES;
print_r($updateOrAdd);
$header = NULL;
$data = array();
}
我的print_r输出在php代码中
Array
(
[articleCsv] => Array
(
[name] => Array
(
[0] => Pmaster Inladen.csv
)
[type] => Array
(
[0] => text/csv
)
[tmp_name] => Array
(
[0] => /Applications/AMPPS/tmp/php/php7VNPlg
)
[error] => Array
(
[0] => 0
)
[size] => Array
(
[0] => 111216
)
)
)
我的密钥(updateOrAdd)在数组中不在哪里?我不明白..