I'm using Jquery-File-Upload for my upload page, and I'm having a problem to add extra upload fields.
I'm following that page: https://github.com/blueimp/jQuery-File-Upload/wiki/How-to-submit-additional-form-data
It works well for 1 file submission. However, with multiple files submission we are starting to see issues, because files are uploaded 1 file / POST (singleFileUploads: true).
The code I'm using as reference is the following:
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<!-- ... -->
<td class="title"><label>Title: <input name="title[]" required></label></td>
<!-- ... -->
</tr>
{% } %}
</script>
If you submit that with 2 files, then you get 2 POSTS:
1/
$_REQUEST:
(
title:
(
[0] -> Title1
[1] -> Title2
)
)
$_FILES:
(
[0] -> ( 'name' => 'file name 1', ... )
)
2/
$_REQUEST:
(
title:
(
[0] -> Title1
[1] -> Title2
)
)
$_FILES:
(
[0] -> ( 'name' => 'file name 2', ... )
)
Then, on php side, the function handle_form_data relies on file index
<?php
// ...
protected function handle_form_data($file, $index) {
// Handle form data, e.g. $_REQUEST['description'][$index]
}
// ...
The problem is that index is always 0, because we're uploading 1 file / post. Now you see that since the $_REQUEST uploads all extra fields from all files (no matter what is it the current file), the index from $_FILES gets de-synchronized from the extra fields array.
Do you know any workaround, except turning singleFileUploads to OFF?