jquery - how to multiply file to upload using icon button -


i start write script allow users click on icon , choose image upload. allow user upload multiply files. how can (using icon button in order open browser dialog)

this done:

jsfiddle.net/wsurube2/

the htmlinputelement type="file" has .multiple property indicates if input can have more 1 value. can access files using element.files collection index.

input.files[index]

https://developer.mozilla.org/en-us/docs/web/api/htmlinputelement/multiple

html: add multiple attribute.

<input type='file' name='file[]' class=' form-control file-field hide' max_files_upload='2' accept="image/jpg,image/png,image/jpeg,image/gif" style="display: none" multiple/> 

http://jsfiddle.net/seanwessell/wsurube2/1/

// validation images     $(function() {         $('input.file-field').on('change', function(e) {             alert(this.files.length);             var filename = $(this).val();             if (!(/\.(gif|jpg|jpeg|tiff|png)$/i).test(filename)) {                 this.value = '';                 $(this).closest('form').find('.filenamebox').html("<span class='valid_msg'>images only!</span>");             }             else                 $(this).closest('form').find('.filenamebox').html("image: " + filename + " <button class='clear_file btn btn-default btn-xs'>remove</button>");       });     }); 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -