I would put the contents of the jquery plugin in web/bundles/<your bundle name>/js/jquery-file-upload. And then I set up a script (check the Options the config), to search for the file index.php at /bundles/<your bundle name>/js/jquery-file-upload/server/php/index.php.
Of course, you will need to modify this index.php file to check if the user is logged in and has rights.
As an example, this is what I did in a test environment:
I added this action to the controller:
public function testJqueryFileUploadAction()
{
return array();
}
And I created this template:
<input id="fileupload" type="file" name="files[]" data-url="{{ asset('bundles/<your bundle name>/jquery-file-upload/server/php/index.php') }}" multiple>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="{{ asset('bundles/<your bundle name>/jquery-file-upload/js/vendor/jquery.ui.widget.js') }}"></script>
<script src="{{ asset('bundles/<your bundle name>/jquery-file-upload/js/jquery.iframe-transport.js') }}"></script>
<script src="{{ asset('bundles/<your bundle name>/jquery-file-upload/js/jquery.fileupload.js') }}"></script>
<script>
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
</script>
source
share