Check if file upload is supported in device or not

Posted: April 16, 2014 in HTML, PHP
Tags: , ,

// Detect file input support
var isFileInputSupported = (function () {
// Handle devices which falsely report support
if (navigator.userAgent.match(/(Android (1.0|1.1|1.5|1.6|2.0|2.1))|(Windows Phone (OS 7|8.0))|(XBLWP)|(ZuneWP)|(w(eb)?OSBrowser)|(webOS)|(Kindle\/(1.0|2.0|2.5|3.0))/)) {
return false;
}
// Create test element
var el = document.createElement("input");
el.type = "file";
return !el.disabled;
})();

if (isFileInputSupported)
$('[name="myfile[]"]').trigger('click');
else
alert('This device does not support File upload.');

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