当我尝试将文件上传到服务器时,我遇到了问题。我以前做了很多次,所以我不确定为什么现在这样。根据我的知识,没有任何改变。
发生的事情如下:
通过上传者
检查标题,清楚地显示 N 文件数量。
测试php文件并放行print_r($_FILES)
行;它只显示一个文件,特别是文件堆栈中的最后一个文件。
仅供参考我正在使用Krajee的jquery插件Bootstrap文件输入。
文件输入插件文档 http://plugins.krajee.com/file-input
JS
$.ajax({
url : '../assets/server/trade/submitTradeForm.php',
type : 'post',
data : data,
dataType : 'JSON',
success : function(response){
if(!response.errors){
if($('#images').get(0).files.length > 0){
$('#images').on('filebatchuploadsuccess', function(event, data, previewId, index){
//$('#tradeForm')[0].reset();
bootbox.alert(data.response.success_message);
});
$('#images').on('filelock', function(event, filestack, extraData){
extraData['trade_form__id'] = response.trade_form__id;
});
$('#images').fileinput('upload');
}else{
bootbox.alert(response.success_message);
}
}else{
bootbox.alert(response.error_message);
}
}
});
PHP
<?php
print_r($_FILES);
if(!empty($_FILES)){
if(!empty($_FILES)){
$names = array();
$files = array();
$mime_types = array();
foreach($_FILES['file']['name'] as $name){
array_push($names, $name);
}
foreach($_FILES['file']['tmp_name'] as $temp){
array_push($files, $temp);
}
foreach($_FILES['file']['type'] as $type){
array_push($mime_types, $type);
}
}
?>
提前感谢您提供任何帮助!
答案 0 :(得分:2)
由于表单未与文件输入的命名方式一起发布,因此每个文件的name
属性要求通过数组访问它。
例如:
带有方括号的 <input type="file" name="file[]">
。
括号声明/表示它是一个数组。
因此,PHP接受了一个文件,只有一个,并且是因为缺少数组声明而使用的最后一个文件。
参考文献: