Simple jQuery Multiple File Image Upload With Preview Plugin

simple-jquery-file-upload

File upload tool with multiple file selection, drag and drop support, progress bars, validation and preview images, audio, and video for jQuery. Supports cross-domain, split, resumable file uploads and client-side image resizing.

Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go, etc.) that supports standard HTML form file uploads.

simple jquery file upload, simple jquery file upload with preview, jquery file upload example, multiple image upload jquery plugin, jquery file upload bs4

How to make use of it:

1. Load the JavaScript libraries into an HTML file.

<!-- Required -->
<script src="/path/to/cdn/jquery.min.js"></script>
<script src="js/vendor/jquery.ui.widget.js"></script>
<script src="js/jquery.iframe-transport.js"></script>
<script src="js/jquery.fileupload.js"></script>

<!-- Audio Preview (OPTIONAL) -->
<script src="js/jquery.fileupload-audio.js"></script>

<!-- Image Preview & Resize (OPTIONAL) -->
<script src="js/jquery.fileupload-image.js"></script>

<!-- Upload Processing (OPTIONAL) -->
<script src="js/jquery.fileupload-process.js"></script>

<!-- User Interface (OPTIONAL) -->
<script src="js/jquery.fileupload-ui.js"></script>

<!-- File Validation (OPTIONAL) -->
<script src="js/jquery.fileupload-validate.js"></script>

<!-- Video Preview (OPTIONAL) -->
<script src="js/jquery.fileupload-video.js"></script>

2. Create an input file and specify the path to the file handler.

<input id="fileupload" type="file" name="files[]" data-url="server/php/index.php" multiple>

3. Attach the plugin to the file entry and specify the type of data the server will return.

$(function () {
  $('#fileupload').fileupload({
    dataType: 'json',
    done: function (e, data) {
      // do something here
    }
  });
});

4. Create a progress bar to visualize the progress of the upload.

<div id="progress">
  <div class="bar" style="width: 0%;"></div>
</div>
$(function () {
  $('#fileupload').fileupload({
    dataType: 'json',
    done: function (e, data) {
      // do something here
    },
    progressall: function (e, data) {
      var progress = parseInt(data.loaded / data.total * 100, 10);
      $('#progress .bar').css(
        'width',
        progress + '%'
      );
    }
  });
});

5. The file loader listens for change events in the specified file input fields by setting fileInput and pasting or dropping the events of the specified drop zone.

$('#fileupload').fileupload({

  // The drop target element(s), by the default the complete document.
  // Set to null to disable drag & drop support:
  dropZone: $(document),

  // The paste target element(s), by the default undefined.
  // Set to a DOM node or jQuery object to enable file pasting:
  pasteZone: undefined,

  // The file input field(s), that are listened to for change events.
  // If undefined, it is set to the file input fields inside
  // of the widget element on plugin initialization.
  // Set to null to disable the change listener.
  fileInput: undefined,

  // By default, the file input field is replaced with a clone after
  // each input field change event. This is required for iframe transport
  // queues and allows change events to be fired for the same file
  // selection, but can be disabled by setting the following option to false:
  replaceFileInput: true,

  // The parameter name for the file form data (the request argument name).
  // If undefined or empty, the name property of the file input field is
  // used, or "files[]" if the file input name property is also empty,
  // can be a string or an array of strings:
  paramName: undefined,

  // By default, each file of a selection is uploaded using an individual
  // request for XHR type uploads. Set to false to upload file
  // selections in one request each:
  singleFileUploads: true,

  // To limit the number of files uploaded with one XHR request,
  // set the following option to an integer greater than 0:
  limitMultiFileUploads: undefined,

  // The following option limits the number of files uploaded with one
  // XHR request to keep the request size under or equal to the defined
  // limit in bytes:
  limitMultiFileUploadSize: undefined,

  // Multipart file uploads add a number of bytes to each uploaded file,
  // therefore the following option adds an overhead for each file used
  // in the limitMultiFileUploadSize configuration:
  limitMultiFileUploadSizeOverhead: 512,

  // Set the following option to true to issue all file upload requests
  // in a sequential order:
  sequentialUploads: false,

  // To limit the number of concurrent uploads,
  // set the following option to an integer greater than 0:
  limitConcurrentUploads: undefined,

  // Set the following option to true to force iframe transport uploads:
  forceIframeTransport: false,

  // Set the following option to the location of a redirect url on the
  // origin server, for cross-domain iframe transport uploads:
  redirect: undefined,

  // The parameter name for the redirect url, sent as part of the form
  // data and set to 'redirect' if this option is empty:
  redirectParamName: undefined,

  // Set the following option to the location of a postMessage window,
  // to enable postMessage transport uploads:
  postMessage: undefined,

  // By default, XHR file uploads are sent as multipart/form-data.
  // The iframe transport is always using multipart/form-data.
  // Set to false to enable non-multipart XHR uploads:
  multipart: true,

  // To upload large files in smaller chunks, set the following option
  // to a preferred maximum chunk size. If set to 0, null or undefined,
  // or the browser does not support the required Blob API, files will
  // be uploaded as a whole.
  maxChunkSize: undefined,

  // When a non-multipart upload or a chunked multipart upload has been
  // aborted, this option can be used to resume the upload by setting
  // it to the size of the already uploaded bytes. This option is most
  // useful when modifying the options object inside of the "add" or
  // "send" callbacks, as the options are cloned for each file upload.
  uploadedBytes: undefined,

  // By default, failed (abort or error) file uploads are removed from the
  // global progress calculation. Set the following option to false to
  // prevent recalculating the global progress data:
  recalculateProgress: true,

  // Interval in milliseconds to calculate and trigger progress events:
  progressInterval: 100,

  // Interval in milliseconds to calculate progress bitrate:
  bitrateInterval: 500,

  // By default, uploads are started automatically when adding files:
  autoUpload: true,
  // By default, duplicate file names are expected to be handled on
  // the server-side. If this is not possible (e.g. when uploading
  // files directly to Amazon S3), the following option can be set to
  // an empty object or an object mapping existing filenames, e.g.:
  // { "image.jpg": true, "image (1).jpg": true }
  // If it is set, all files will be uploaded with unique filenames,
  // adding increasing number suffixes if necessary, e.g.:
  // "image (2).jpg"
  uniqueFilenames: undefined,

  // Error and info messages:
  messages: {
    uploadedBytes: 'Uploaded bytes exceed file size'
  },

  // Translation function, gets the message key to be translated
  // and an object with context specific data as arguments:
  i18n: function(message, context) {
    // eslint-disable-next-line no-param-reassign
    message = this.messages[message] || message.toString();
    if (context) {
      $.each(context, function(key, value) {
        // eslint-disable-next-line no-param-reassign
        message = message.replace('{' + key + '}', value);
      });
    }
    return message;
  },

  // Additional form data to be sent along with the file uploads can be set
  // using this option, which accepts an array of objects with name and
  // value properties, a function returning such an array, a FormData
  // object (for XHR file uploads), or a simple object.
  // The form of the first fileInput is given as parameter to the function:
  formData: function(form) {
    return form.serializeArray();
  },

  // The add callback is invoked as soon as files are added to the fileupload
  // widget (via file input selection, drag & drop, paste or add API call).
  // If the singleFileUploads option is enabled, this callback will be
  // called once for each file in the selection for XHR file uploads, else
  // once for each file selection.
  //
  // The upload starts when the submit method is invoked on the data parameter.
  // The data object contains a files property holding the added files
  // and allows you to override plugin options as well as define ajax settings.
  //
  // Listeners for this callback can also be bound the following way:
  // .bind('fileuploadadd', func);
  //
  // data.submit() returns a Promise object and allows to attach additional
  // handlers using jQuery's Deferred callbacks:
  // data.submit().done(func).fail(func).always(func);
  add: function(e, data) {
    if (e.isDefaultPrevented()) {
      return false;
    }
    if (
      data.autoUpload ||
      (data.autoUpload !== false &&
        $(this).fileupload('option', 'autoUpload'))
    ) {
      data.process().done(function() {
        data.submit();
      });
    }
  },

  // Events.
  // You can also fire the events using .on(Event, function(){...});

  // Callback for the submit event of each file upload:
  submit: function (e, data) {},

  // Callback for the start of each file upload request:
  send: function (e, data) {},

  // Callback for successful uploads:
  done: function (e, data) {},

  // Callback for failed (abort or error) uploads:
  fail: function (e, data) {},

  // Callback for completed (success, abort or error) requests:
  always: function (e, data) {}, 

  // Callback for upload progress events:
  progress: function (e, data) {},

  // Callback for global upload progress events:
  progressall: function (e, data) {},

  // Callback for uploads start, equivalent to the global ajaxStart event:
  start: function (e) {},

  // Callback for uploads stop, equivalent to the global ajaxStop event:
  stop: function (e) {}, 

  // Callback for change events of the fileInput(s):
  change: function (e, data) {},

  // Callback for paste events to the pasteZone(s):
  paste: function (e, data) {},

  // Callback for drop events of the dropZone(s):
  drop: function (e, data) {}, 

  // Callback for dragover events of the dropZone(s):
  dragover: function (e) {},

  // Callback before the start of each chunk upload request (before form data initialization):
  chunkbeforesend: function (e, data) {}, 

  // Callback for the start of each chunk upload request:
  chunksend: function (e, data) {},

  // Callback for successful chunk uploads:
  chunkdone: function (e, data) {}, 

  // Callback for failed (abort or error) chunk uploads:
  chunkfail: function (e, data) {},

  // Callback for completed (success, abort or error) chunk upload requests:
  chunkalways: function (e, data) {},

  // The plugin options are used as settings object for the ajax calls.
  // The following are jQuery ajax settings required for the file uploads:
  processData: false,
  contentType: false,
  cache: false,
  timeout: 0
  
});

Features

  • Multiple file upload:
    Allows to select multiple files at once and upload them simultaneously.
  • Drag & Drop support:
    Allows uploading files by dragging them from your desktop or file manager and dropping them on your browser window.
  • Upload progress bar:
    Shows a progress bar indicating the upload progress for individual files and for all uploads combined.
  • Cancelable uploads:
    Individual file uploads can be canceled to stop the upload progress.
  • Resumable uploads:
    Aborted uploads can be resumed with browsers supporting the Blob API.
  • Chunked uploads:
    Large files can be uploaded in smaller chunks with browsers supporting the Blob API.
  • Client-side image resizing:
    Images can be automatically resized on the client-side with browsers supporting the required JS APIs.
  • Preview images, audio, and video:
    A preview of image, audio, and video files can be displayed before uploading with browsers supporting the required APIs.
  • No browser plugins (e.g. Adobe Flash) are required:
    The implementation is based on open standards like HTML5 and JavaScript and requires no additional browser plugins.
  • Graceful fallback for legacy browsers:
    Uploads files via XMLHttpRequests if supported and uses iframes as a fallback for legacy browsers.
  • HTML file upload form fallback:
    Allows progressive enhancement by using a standard HTML file upload form as a widget element.
  • Cross-site file uploads:
    Supports uploading files to a different domain with cross-site XMLHttpRequests or iframe redirects.
  • Multiple plugin instances:
    Allows using multiple plugin instances on the same webpage.
  • Customizable and extensible:
    Provides an API to set individual options and define callback methods for various upload events.
  • Multipart and file contents stream uploads:
    Files can be uploaded as standard “multipart/form-data” or file contents stream (HTTP PUT file upload).
  • Compatible with any server-side application platform:
    Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go, etc.) that supports standard HTML form file uploads.

Beautiful jQuery File Upload Plugin with Bootstrap, jQuery File Upload Github, blueimp jquery file upload php example


See Demo And Download

Official Website(blueimp): Click Here

This superior jQuery/javascript plugin is developed by blueimp. For extra advanced usage, please go to the official website.