使用jquery文件上传后上传输入文件字段为空

时间:2022-11-13 22:55:51

I'm trying to upload files and save the links in to my database with the jquery file upload plugin and the OneupUploaderBundle in Symfony.

我正在尝试使用jquery文件上传插件和Symfony中的OneupUploaderBundle上传文件并将链接保存到我的数据库中。

I have an input file field in my form like this:

我的表单中有一个输入文件字段,如下所示:

<input class="form-control" id="fileupload" type="file" name="files[]" data-url="{{ oneup_uploader_endpoint('gallery') }}" multiple />

In my jQuery I have this:

在我的jQuery中我有这个:

$('#form-Entity').submit(function (e) {
    e.preventDefault();
});

$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        $("#submitentity").on('click', function () {
            data.submit();
        });
    },
    done: function (e, data) {
        console.log(data);
        $('#form-Entity')[0].submit();
    }
});

First I prevent the form from submitting. Then I upload the files. But when they are uploaded and I want to submit the form, the input files field is empty so I don't get anything in my backend ... . Also when I select images my input field still says 'no files selected'.

首先,我阻止表单提交。然后我上传文件。但是当他们上传并且我想提交表单时,输入文件字段是空的,所以我的后端没有任何东西......此外,当我选择图像时,我的输入字段仍然显示“未选择文件”。

How can I fix this?

我怎样才能解决这个问题?

1 个解决方案

#1


0  

I created a list and every time a file is uploaded I add it to the list. At the end, before submitting the form I set the value of the hidden input field with the list.

我创建了一个列表,每次上传文件时都会将其添加到列表中。最后,在提交表单之前,我使用列表设置隐藏输入字段的值。

#1


0  

I created a list and every time a file is uploaded I add it to the list. At the end, before submitting the form I set the value of the hidden input field with the list.

我创建了一个列表,每次上传文件时都会将其添加到列表中。最后,在提交表单之前,我使用列表设置隐藏输入字段的值。