Multy File Upload File Name in Jquery

jQuery MultiFile

The unopinionated manner to implement file pick.

What this is

This jQuery Multiple File Pick Plugin ($.MultiFile) is a non-obstrusive plugin for jQuery that helps users easily select multiple files for upload. It lets you apply some basic restrictions/validation so you lot can easily reject files earlier they're uploaded based on their extension or size before they're uploaded.

What this isn't

This is non a file upload tool. Uploading files require server-side integration and security considerations this projection will never support. We tin recommend many, many, many smashing tools if you're looking for a complete upload solution. But if you don't already manage your own server-side integration, or if you accept no idea what I'k talking about, then this plugin is not for you.

What's new?

A fresh showtime... ish : This project started a a very long time ago... and it's been dormant since 2009! Support has been shockingly bad, we admit, but nosotros would like to engage more actively with our users and the jQuery community from now on. And so as of April 2014, we've left Google Code backside and volition exist starting a fresh projection on GitHub. Our other projects (Star Rating & CKEditor will follow shortly). We very much encourage and would love you all to report bug, contribue and discuss this project on GitHub.

Getting started

Just add the multi class to your file input chemical element.

              <input blazon="file" class="multi"/>            

Use the maxlength property if you want to limit the number of files selected.

              <input type="file" form="multi" maxlength="2"/>            

Utilize the accept property if yous only want files of a certain extension to be selected.
Separate valid extensions with a "|", like this: "jpg|gif|png".

              <input type="file" class="multi" accept="gif|jpg"/>            

NB.: server-side validation is always required

Usage Examples

Using Attributes

The easiest way to get started is to add together class="multi" and modify the attributes of your element

Example i

Use maxlength to limit the number of files selected

                    <input   course="multi"   maxlength="2" />                  

Limit: 2 files.
Allowed extensions: any.

Case 2

Use accept to limit the extensions allowed

                    <input   class="multi"   take="gif|jpg" />                  

Limit: no limit.
Allowed extensions: gif and jpg.

Example 3

Use maxlength and take combined

                    <input   grade="multi"   accept="gif|jpg"   maxlength="3" />                  

Limit: iii files
Immune extensions: gif, jpg.

Note that server-side validation is always required

Using the class property

There is a mode to configure the plugin via the grade property, without any knowledge of javascript

Case 4
                    <input class="   multi max-3 "/>                  

Limit: 3 files.
Allowed extensions: any.

Case 5
                    <input class="   multi accept-gif|jpg "/>                  

Limit: no limit.
Allowed extensions: gif, jpg.

Instance vi
                    <input class="   multi   max-three   accept-gif|jpg   maxsize-1024 "/>                  

Limit: 3 files
Allowed extensions: gif, jpg.
Max payload: 1MB (1024 bytes)

Note that server-side validation is e'er required

Selecting many files at once (HTML5)

So far, each of the example higher up has only enabled you lot to select 1 file at a time. To select multiple files at one time, merely utilize HTML5'due south multiple aspect (1, ii)

Example 7
                    <input   multiple   form="multi"   maxlength="10" />                  

Limit: 10 files.
Allowed extensions: any.

Example 8
                    <input   multiple   form="multi"   take="gif|jpg|png" />                  

Limit: no limit.
Allowed extensions: gif, jpg.

Example 9
                    <input   multiple   class="multi"   maxlength="10"   accept="gif|jpg|png" />                  

Limit: 10 files
Allowed extensions: gif, jpg, png.

Note that server-side validation is always required

Validating Sizes

It'southward common to validate the size of the files being selected prior to upload.

Example 10a

Using class maxsize-* (* = max size in kb)

                    <input   multiple   class="multi maxsize-5120" />                  

Limit: whatever number of files
Allowed extensions: any.
Max payload: 5MB

Example 10b

Using data-maxsize attribute (max size in kb)

                    <input   multiple   class="multi"   maxlength="three"   data-maxsize="1024" />                  

Limit: 3 files (under <1MB in total)

Example 10c

Use data-maxfile to validate private files

                    <input   multiple   class="multi"   maxlength="iii"   information-maxfile="1024" />                  

Limit: 3 files (under <1MB each)

Annotation that server-side validation is always required

With an Prototype Preview

There's an easy style to add together a preview of the image existence uploaded

Instance 11a

Using class with-preview

                    <input   multiple   class="multi with-preview" />                  

Advanced Examples

IMPORTANT: Don't use class="multi" if you lot use any of the examples below this point.

If you lot use class="multi" the plugin will exist initialised automatically (taking precedence over your lawmaking).

You must invoke the plugin with your own selector when you utilise any of the examples beneath.

Something like

                    <input type="file" class="this-is-your-form" />                  

.

Followed by

                    // this is your code $(function(){ // wait for page to load      // this is your selector   $('input.this-is-your-class').MultiFile({     // your options go hither     max: ii,     take: 'jpg'   });  });                  

Setting limit via script

                    <input multiple type="file" id="UpTo3Files"/>                  
                    // wait for document to load $(function(){      // upwardly to 3 files tin can exist selected    // invoke plugin   $('#UpTo3Files').MultiFile(5);    // if you lot send in a number the plugin   // will care for it equally the file limit  });                  

Endeavor information technology:

Limit and Extension Filter

                    <input multiple type="file" id="UpTo3Images"/>                  
                    // expect for document to load $(function(){      // upward to 3 files tin can be selected   // but images are immune    // invoke plugin   $('#UpTo3Images').MultiFile({     max: iii,      accept: 'gif|jpg|png'   });  });                  

Try it:

Multi-lingual support

                    <input multiple type="file" id="EmPortugues"/>                  
                    // expect for document to load $(office(){      // use a different language   // $file prints the file proper noun   // $ext prints the file extension    // invoke plugin   $('#EmPortugues').MultiFile({      max: 3,      take: 'gif|jpg|png'     Cord: {        remove:'Remover',        selected:'Selecionado: $file',        denied:'Invalido arquivo de tipo $ext!'      }    });  });                  

Try information technology:

Moving the file listing

This example populates the file list in a custom element

                        $(function() { // wait for document to load    $('#T7').MultiFile({     list: '#T7-listing'   }); });                      

This is div#T7-listing - selected files will be populated here...

Customising the file list

Use a custom 'remove' paradigm in the file list

                      $(role() { // wait for certificate to load    $('#T8A').MultiFile({     STRING: {       remove: '<img src="/i/bin.gif" height="16" width="16" alt="x"/>'     }   }); });                    

Customising all list content

                    $(office() { // expect for certificate to load    $('#T8B').MultiFile({     STRING: {       file: '<em title="Click to remove" onclick="$(this).parent().prev().click()">$file</em>',       remove: '<img src="/i/bin.gif" top="xvi" width="16" alt="x"/>'     }   }); });                  

Using events

The arguments passed on to each event handler are:
chemical element: file element which triggered the event
value: the value of the element in question
master_element: the original element containing all relevant settings

Selection events:

  • onFileAppend
  • afterFileAppend
  • onFileSelect
  • afterFileSelect
  • onFileRemove
  • afterFileRemove

Validation events:

  • onFileDuplicate
  • onFileInvalid
  • onFileTooMany
  • onFileTooBig
  • onFileTooMuch
                          <input multiple type="file" id="WithEvents"/>                        
                          // wait for certificate to load $(function(){      // 2 jpgs under 100kb only    $('#WithEvents').MultiFile({     max: ii,     max_size: 100,     accept: 'jpg',     onFileRemove: function(element, value, master_element) {       $('#F9-Log').append('<li>onFileRemove - ' + value + '</li>')     },     afterFileRemove: part(element, value, master_element) {       $('#F9-Log').append('<li>afterFileRemove - ' + value + '</li>')     },     onFileAppend: function(element, value, master_element) {       $('#F9-Log').suspend('<li>onFileAppend - ' + value + '</li>')     },     afterFileAppend: function(element, value, master_element) {       $('#F9-Log').suspend('<li>afterFileAppend - ' + value + '</li>')     },     onFileSelect: function(element, value, master_element) {       $('#F9-Log').append('<li>onFileSelect - ' + value + '</li>')     },     afterFileSelect: function(element, value, master_element) {       $('#F9-Log').append('<li>afterFileSelect - ' + value + '</li>')     },     onFileInvalid: function(element, value, master_element) {       $('#F9-Log').suspend('<li>onFileInvalid - ' + value + '</li>')     },     onFileDuplicate: function(element, value, master_element) {       $('#F9-Log').append('<li>onFileDuplicate - ' + value + '</li>')     },     onFileTooMany: function(chemical element, value, master_element) {       $('#F9-Log').append('<li>onFileTooMany - ' + value + '</li>')     },     onFileTooBig: function(element, value, master_element) {       $('#F9-Log').suspend('<li>onFileTooBig - ' + value + '</li>')     },     onFileTooMuch: part(element, value, master_element) {       $('#F9-Log').append('<li>onFileTooMuch - ' + value + '</li>')     }   }); });                        

This is div#F9-Log - selected files will be populated here...

Multi-lingual support

The plugin doesn't have any additional languages built-in, only it's very easy to customise the messages to any language of your choosing. Run across the examples below...

NB.: This example has been configured to accept gif/pg files only in order to demonstrate the fault messages.

Method ane: Using form property (requires the MetaData plugin)

            <input type="file"   form="multi {     have:'gif|jpg',     max:3,     Cord:{        remove:'Remover',        selected:'Selecionado: $file',        denied:'Invalido arquivo de tipo $ext!',        duplicate:'Arquivo ja selecionado:\northward$file!'      }    }" />          

Method 2: Programatically by ID (One element but, does not require MetaData plugin)

            <input type="file" id="PortugueseFileUpload" />          
            $(function(){   $('#PortugueseFileUpload').MultiFile({     accept:'gif|jpg',      max:3,      STRING: {       remove:'Remover',         selected:'Selecionado: $file',        denied:'Invalido arquivo de tipo $ext!',        duplicate:'Arquivo ja selecionado:\n$file!'     }   }); });          

Method 3: Programatically ( n emlements, does not require MetaData plugin)

Run into this feature request for details

            <input type="file" class="multi-pt" /> <input type="file" class="multi-pt" /> <input type="file" class="multi-pt" />          
            $(function(){   $('.multi-pt').MultiFile({     accept:'gif|jpg',      max:three,      String: {        remove:'Remover',        selected:'Selecionado: $file',        denied:'Invalido arquivo de tipo $ext!',        duplicate:'Arquivo ja selecionado:\northward$file!'     }   }); });          

Installation

Requirements

Y'all'll demand jQuery, we recommend using Google Hosted Libraries.

            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" type="text/javascript" language="javascript"></script>          

The plugin

Either download the latest version and host it on your ain server

            <script src="path/to/your/jquery.MultiFile.js" type="text/javascript" language="javascript"></script>          

OR if you like living on the edge, hotlink the latest release directly from GitHub

            <script src="//github.com/fyneworks/multifile/blob/master/jQuery.MultiFile.min.js" type="text/javascript" language="javascript"></script>          

Support

We very much encourage and would love you all to report issues, contribue and talk over this projection on GitHub.

There's besides a README.md for quick reference, if you're that fashion inclined.

This project started a a very long fourth dimension agone... and it's been dormant since 2009! Support has been shockingly bad, nosotros admit, but nosotros would like to engage more actively with our users and the jQuery community from at present on. So as of April 2014, nosotros've left Google Code behind and will be starting a fresh projection on GitHub. Our other projects (Star Rating & CKEditor will follow shortly).

Credit where it'south due!

  • Fyneworks.com professional web design and google SEO experts
  • Dean Edwards - Author of JS Packer used to compress the plugin
  • Adrian Wróbel - Fixed a nasty bug so the script could work perfectly in Opera
  • Jonas Wagner - Modified plugin then newly created elements are an exact re-create of the original element (ie.: persists attributes)
  • Mike Alsup - Author of several jQuery Plugins...
    • Suggested solution to chemical element naming convention / server-side treatment
    • Course plugin - Used to submit forms via ajax
    • blockUI plugin - Used to testify pretty fault messages
  • Julien Phalip - Identified conflict with variable name 'class' in several methods

License Info

Multiple File Choice Plugin by Fyneworks.com is licensed, equally jQuery is, nether the MIT License. Creative Commons License

choaboody.blogspot.com

Source: http://lampspw.wallonie.be/dgo4/tinymvc/myfiles/plugins/multifile-2.2.1/docs.html

Related Posts

0 Response to "Multy File Upload File Name in Jquery"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel