Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if browser supports file uploading? (Mobile + Desktop)

I'm developing an application for both mobile and desktop browsers. I'm wondering if there is anyway to detect if a browser supports file uploading. I'm looking specifically for feature detection and not browser detection. Is there any way to find out?

Server-side or client side is fine.

Thanks

like image 223
Sunjay Varma Avatar asked Feb 16 '12 02:02

Sunjay Varma


2 Answers

client side javascript:

<input type="file" name="file" value="" id="fileUploadField1">      
<script type="text/javascript" charset="utf-8">
    if (document.getElementById('fileUploadField1').disabled)
        { document.write('your device does not allow uploads');     }
        else
        { document.write('your device does allow uploads');     }
</script>
like image 115
Steve Wasiura Avatar answered Nov 06 '22 19:11

Steve Wasiura


You might be interested to read this article about current input type=file support on mobile and how to detect it: http://viljamis.com/blog/2012/file-upload-support-on-mobile/ (the detection is currently tested to be working on ~120 different mobile browser/mobile OS combinations).

Basically, we are just using similar detection as Modernizr does, but use UA detection as a backup to filter out those mobile browsers that falsely report support (there really doesn’t seem to be any other way to detect it reliably than using these both, feature detection and browser detection).

like image 7
Viljami S. Avatar answered Nov 06 '22 18:11

Viljami S.