Get selected file(s) from html file input

//Working with single photo input
var $fileInput = $(‘#photo’)[0];
var $photo = $fileInput.files[0];
if ($photo == null) {
    alert(“Please take photo.”); return;
}
fd.append(“photos”, $photo);


//Working with multiple photo input
var inputs = $(‘.multiplephoto’);
$.each(inputs, function (obj, v) {
    var file = v.files[0];
    if (file==null) {
        alert(“select photo”);
    }
    fd.append(“photos”, file);            
});
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s