innostudio / fileuploader

Beautiful and powerful HTML file uploading tool. A jQuery, PHP and Node.js plugin that transforms the standard input into a revolutionary and fancy field on your page.
141 stars 25 forks source link

Dynamic upload URL #45

Closed rabat1313 closed 4 years ago

rabat1313 commented 4 years ago

Is it possible to make dynamic AJAX upload URL (to PHP) which contains the name of input?

innostudio commented 4 years ago

@rabat1313 there are 2 solutions that I would use:

1. Two inputs, one name, one php

<input type="file" name="files" id="files_1">
<input type="file" name="files" id="files_2">
var fileuploaderConfig = {
    limit: 10,
    upload: {
        url: 'php/ajax.php'
    }
};

$('#files_1').fileuploader(fileuploaderConfig);
$('#files_2').fileuploader($.extend({}, fileuploaderConfig, {
    limit: 20
}));
<?php

$FileUploader = new FileUploader('files', array());

2. Two inputs, name over ajax

<input type="file" name="files" id="files_1">
<input type="file" name="files" id="files_2">
var fileuploaderConfig = {
    limit: 10,
    upload: {
        url: 'php/ajax.php',
        beforeSend: function(item, listEl, parentEl, newInputEl, inputEl) {
            item.upload.data._input = inputEl.attr('name');
        }
    }
};

$('#files_1').fileuploader(fileuploaderConfig);
$('#files_2').fileuploader($.extend({}, fileuploaderConfig, {
    limit: 20
}));
<?php
$inputName = isset($_POST['_input']) ? $_POST['_input'] : 'files';

$FileUploader = new FileUploader($inputName, array(
    'required' => true
));