11

I am trying on Firefox,IE 9,Chrome and Opera the code below ,but the onInitFs(fs) function doesn't get called.if I add '()' to onInitFs in the window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler) that function get called but fs is null ? Does anybody know how to solve this problem?I try on windows 7.I'll appreciate very much your help.

<!DOCTYPE HTML>
`<html>
    <head>  
    <script>
        function errorHandler(e){
            alert("errorrrr");
        }
        function onInitFs(fs){
        alert("onInitFs");
        }
        function readClick(){
                 if (window.webkitRequestFileSystem) {
                     window.webkitRequestFileSystem(window.PERSISTENT, 1024*1024,onInitFs,errorHandler);
                } 
                 else {
                    window.requestFileSystem(window.PERSISTENT, 1024*1024, onInitFs, errorHandler);
                }

            alert("read finishsssss");
        }
        </script>
    </head>
<body>
<input type="button" value="Read dir" onclick="readClick()">
    <ul id="filelist"></ul>
</body>
</html>
Rob W
  • 341,306
  • 83
  • 791
  • 678
Tony2
  • 111
  • 1
  • 1
  • 4
  • Related: http://stackoverflow.com/questions/19802032/how-can-a-chrome-extension-save-many-files-to-a-user-specified-directory/19813816#comment71099517_19813816 – Pacerier Jan 31 '17 at 14:47

2 Answers2

14

Only chrome supports requestFileSystem as the webkitRequestFileSystem version.

None of the other browsers (FF6, IE9, Op11) support this

Raynos
  • 166,823
  • 56
  • 351
  • 396
  • 1.thnx but I am trying on chrome as well with webkitRequestFileSystem and the onInitFs(fs) function doesn't work ie doesn't get called – Tony2 Jul 23 '11 at 20:43
  • 2.my second question is:do you now any way of getting the list of files of a given folder which would work in almost all browsers? – Tony2 Jul 23 '11 at 20:48
  • @Tony2 no. requestFileSystem gives you a sandboxed file system. You cant access local files directly. You can ask users to upload a file through `` though – Raynos Jul 23 '11 at 20:57
  • i appreciate very much your responses,but i don't want to ask user.I need to load from code one by one the images of a given folder without using the trick of naming images like this image1.jpg,image2.jpg,etc in other words images'names are unchangeable .any idea? – Tony2 Jul 23 '11 at 21:12
  • there will be about 100 images – Tony2 Jul 23 '11 at 21:15
  • 7
    @tony2 **You cannot arbitarly access local files using javascript** – Raynos Jul 23 '11 at 21:23
  • thank you very much.what if i use php ?can be done any trickby using it for client side please help – Tony2 Jul 23 '11 at 22:45
  • 1
    @Tony2 the only way to access local files on a users computer would be to use ActiveX (IE only) or Java. Be wary that your **forced to use those to bypass security checks**. Browser **do not allow you to access local files because it's unsecure** – Raynos Jul 23 '11 at 22:47
  • @Raynos you really shouldn't assume JavaScript cannot run in different context when that's possible such as chrome apps and extensions. – zumalifeguard Sep 21 '20 at 04:28
5

Disregarding the security issue that you cannot "browse" local files with a website, your question should be answered:

When requesting a PERSISTENT filesystem you have to request a quota in first. Try that instead:

window.storageInfo.requestQuota(PERSISTENT, 1024*1024, 
    function(grantedBytes) {
        window.requestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
    }, 
    errorHandler
);
Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62