I am trying to find out if browser has ability to select folders, not just multiple files. Current Chrome supports this (example: http://html5-demos.appspot.com/static/html5storage/demos/upload_directory/index.html).
Apparently, it works in Chrome when <input type="file" />
has webkitdirectory
attribute. But how can I test if browser is actually capable of selecting folders and iterating through files?
Web browsers (and JavaScript) can only access local files with user permission. To standardize the file access from the browser, the W3C published the HTML5 File API in 2014. It defines how to access and upload local files with file objects in web applications.
Another good approach is to encapsulate feature detection into a set of functions that can then be used throughout the code. Here's a best practice for detecting whether the browser supports the HTML5 <canvas> element and if so, makes sure that the canvas. getContext('2d') method is working as well.
Using Google Chrome to access local files is as easy as pressing Ctrl + O at the same time. This interface will open, allowing you to navigate to whichever file or folder is needed. There are several types of files which can be opened using Chrome. These include pdf, mp3 files, some video files and most document files.
Maybe this is a solution for your problem:
function isInputDirSupported() {
var tmpInput = document.createElement('input');
if ('webkitdirectory' in tmpInput
|| 'mozdirectory' in tmpInput
|| 'odirectory' in tmpInput
|| 'msdirectory' in tmpInput
|| 'directory' in tmpInput) return true;
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With