Skip to content

Instantly share code, notes, and snippets.

@micc83
Last active January 4, 2019 07:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micc83/5939342 to your computer and use it in GitHub Desktop.
Save micc83/5939342 to your computer and use it in GitHub Desktop.
Multifile uploader with images preview
<form method="post" id="tiribi" enctype="multipart/form-data">
<input id="fileuploader" type="file" name="file[]" multiple="" >
<ul class="filelist"></ul>
<input type="submit" class="button" name="multi_post_submit" value="Upload files" id="submit_button" />
</form>
$(function(){
var anyWindow = window.URL || window.webkitURL;
$("#fileuploader").change(function () {
var uploader = $(this)[0];
// Reset file list
$('ul.filelist').html('');
for ( var i = 0; i < uploader.files.length; ++i ) {
var name = uploader.files.item(i).name.split('.').shift();
var filePreview = jQuery('<li/>', {
text: name,
class: 'animated fadeInLeft'
});
$(filePreview).appendTo('ul.filelist');
var imageUrl = anyWindow.createObjectURL(uploader.files[i]);
var imagePreview = jQuery('<img/>', {
alt: name,
src: imageUrl,
width: 60,
height: 60
});
$(imagePreview).prependTo(filePreview);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment