Last active
January 4, 2019 07:15
-
-
Save micc83/5939342 to your computer and use it in GitHub Desktop.
Multifile uploader with images preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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