我想在表单中的隐藏输入字段中添加上传到数组的文件名。这就是我的形式:
<input type="hidden" name="myFiles[]" id="myFiles" value="">
这是我的文件上载:
$('#fileupload').fileupload({
dataType: 'json',
add: function (e, data) {
$("#submitentity").on('click', function () {
data.submit();
});
},
done: function (e, data) {
var filename = data.files[0]['name'];
var type = data.files[0]['type'];
var row = [];
row["name"] = filename;
row["type"] = type;
myList[i] = row;
i++;
e.preventDefault();
},
stop: function(e){
$("#myFiles").val(myList);
console.log(myList);
submitForm();
}
});
function submitForm(){
$('#form-Entity')[0].submit();
}
正如您所看到的,我有console.log(myList)显示的内容:
[Array[0], Array[0]]
0: Array[0]
length: 0
name: "Hollowbody 4.gif"
type: "image/gif"
1: Array[0]
length: 0
name: "Hollowbody 5.gif"
type: "image/gif"
然后我提交表格。但是在我的后端我得到了
array (size=1)
0 => string '' (length=0)
当我想检查myFiles时......
我做错了什么?
更新:
if ($request->getMethod() == 'POST')
{
$form->bind($request);
$data = $form->getData();
if($form->isValid())
{
$data = $form->getData();
var_dump($request->request->get('myFiles'));
die();
答案 0 :(得分:0)
我按照David的建议创建了逗号分隔列表。就这样做了:
myList += filename;
myList += ',';
myList += type;
myList += ',';