jQuery Plugin Configuration

Usage

When you use the jQuery .filePicker plugin you can pass an object with options:

$('#filepicker').filePicker({
    url: 'uploader/index.php',
    maxFileSize: 10000000,
});

Options

url

Url to the PHP file where the upload is handled.

  • Type: String
  • Default: n\a
  • Example uploader/index.php

data

Used to send data to the server.

  • Type: Object, Function
  • Default n/a
  • Example: {paramA : 'value 1', paramB: 'value 2'}

Or using a function:

data: function() { 
    return {
        paramA: 'value 1',
        paramB: $('#myinput').val(),
    } 
},

On the server side using the events you can access the data with:

$handler->on('upload.before', function ($file) use ($handler) {
    $valueA = $handler->request()->get('paramA'); // <=> $_POST['paramA']
    $valueB = $handler->request()->get('paramB'); // <=> $_POST['paramB']
});

acceptFileTypes

The accepted file types.

  • Type: String (regular expression)
  • Default: n/a
  • Example /(\.|\/)(gif|jpe?g|png)$/i

Warning: Make sure to also set the accept_file_types PHP option too!

imageFileTypes

Files that should be handled as images. Used when displaying the thumbnail preview.

  • Type: String (regular expression)
  • Default: /(\.|\/)(gif|jpe?g|png)$/i

minFileSize

The minimum file size in bytes required.

  • Type: Number
  • Default: 1
  • Example 1000 (= 1 Kilobyte)

maxFileSize

The maximum file size in bytes allowed.

  • Type: Number
  • Default: n/a
  • Example 10000000 (= 10 Megabyes)

fileInput

The jQuery object / selector for the file input button.

  • Type: jQuery Object/ String
  • Default: input[type="file"] (inside the container)
  • Example: $('.file-input-btn')

uploadMultiple

Whether to upload multiple files in a single request.

  • Type: Boolean
  • Default: false

When this is enabled you should not have a "Cancel" button for each file in the ui, because canceling one file will cancel the entire request with all the files.

uploadMultipleLimit

The number of files to upload when uploading multiple files in one request.

  • Type: Number
  • Default: n/a

uploadMultipleSize

The max size in bytes of each request when uploading multiple files in one request.

  • Type: Number
  • Default: n/a
  • Example: 10000000 (= 10 Megabyes)

parallelUploads

The number of upload requests at the same time.

  • Type: Number
  • Default: n/a

plugins

An array of plugins to be used (ui, crop, drop, camera).

  • Type: Array
  • Default: []
  • Example: ['ui', 'drop']

messages

An object with all error messages.

  • Type: Object
  • Default:
{
    uploadFallback: 'The browser does not support file uploads.',
    minFileSize: 'The file must be at least :min KB.',
    maxFileSize: 'The file may not be greater than :max KB.',
    postMaxSize: 'The file exceeds the post max size limit of :max MB.',
    invalidFileType: 'The file type is not allowed.',
    error: 'Oops! Something went wrong.',
    abort: 'The operation was aborted.'

    // UI plugin
    processing: 'Processing...',
    deleteFail: 'Could not delete file :file.',

    // Camera plugin
    cameraError: 'Could not access the camera.',
    cameraFallback: 'Your browser does not support the camera feature.',

    // Crop plugin
    cropLoadFail: 'Could not load the image.',
    cropSaveFail: 'Could not save the image.'
}