When creating a new instance of the jQuery .filePicker
plugin you can pass various options:
$('#filepicker').filePicker({
debug: true,
url: 'uploader/index.php',
autoUpload: false,
});
If enabled, more detailed error messages will be shown on every error that occurs, otherwise a simple generic error is shown.
false
Url to the PHP file where the upload is handled.
n\a
uploader/index.php
Used to pass data to the server.
n/a
{paramA : 'value 1', paramB: 'value 2'}
Or using a function:
formData: function() {
return {
paramA: 'value 1',
paramB: $('#myinput').value(),
}
},
On the server side in any of the handler events you can access the data with $_POST
(or $_GET
when loading the files).
$handler->on('upload.before', function(Event $e) {
$value = $_POST['paramA'];
});
Warning: If you allow users to upload files, don't pass their user id and then save the file based on that. Use sessions instead.
Whether to auto upload the file(s) right after selection.
true
Whether to auto load the files from the server.
false
Add the new files to the beginning of the file list.
true
The accepted file types.
n/a
/(\.|\/)(gif|jpe?g|png)$/i
Warning: Make sure to also set the accept_file_types PHP option ! This is just so the file is not set to server if the JavaScript validation fails. But it's not a safe way of preventing users from uploading unwanted files to the server.
Files that should be handled as images. Used when displaying the thumbnail preview.
/(\.|\/)(gif|jpe?g|png)$/i
The minimum file size required (in Bytes).
1
1000
(= 1 Kilobyte)The maximum file size allowed (in Bytes).
n/a
10000000
(= 10 Megabyes)The maximum number of files allowed to be uploaded.
Warning: Make sure to also set the max_number_of_files PHP option !
n/a
20
The size of the preview thumbnail.
[64, 64]
An array with all error messages.
{
acceptFileTypes: 'The file type is not allowed.',
maxFileSize: 'The file exceeds the maximum allowed file size.',
minFileSize: 'The file size is too small.',
maxNumberOfFiles: 'Maximum number of files exceeded.',
error: 'Oops! Something went wrong.',
browser: 'Please upgrade your browser!',
}
The jQuery object for the file input button.
element.find('input[type="file"]')
$('.file-input-btn')
The jQuery object for the start uploading all queued files button.
element.find('.start')
$('.start-all-btn')
The jQuery object for the cancel all files in the upload queue button.
element.find('.cancel')
$('.cancel-all-btn')
The jQuery object for the delete all files button.
element.find('.delete')
$('.delete-all-btn')
The jQuery object for the list / table where the files are appended or prepended.
element.find('.files')
$('.files-list')
The jQuery object for the drop target.
$(document)
$('.drop-zone')
The jQuery object for drop window that will be shown in the dropZone.
element.find('.drop-window')
$('.other-drop-window')
The ID of the template used to render the file before it's uploaded.
templateUpload
The ID of the template used to render the file after it's uploaded.
templateDownload
An array of selectors used to attach events for the files in the file list.
{
cancel: '.cancel',
start: '.start',
destroy: '.delete',
preview: '.preview',
error: '.error',
progressbar: '.progress-bar'
}
If you use the script with a filesList you can have templates with the HTML that will be appended / prepended to the file list.
There are 2 templates, one used to render the file before it's uploaded and another one to render the file after it's uploaded. You can find examples for both templates in the index.html
and basic-list.html
.
Inside the template you can access the file object properties, add if statements, etc.
<%= file.name %>
<% if (file.error) { %>
<%= file.error %>
<% } %>
<% if (file.url) { %>
<a href="<%= file.url %>"><%= file.name %></a>
<% } else { %>
<%= file.name %>
<% } %>
Read more about the templates here.