Open sd card in android to upload file to my php server using phone latch

I want to go to the file selection from the SD card and upload it to the server. Is it possible to access the SD card in android via phone records, as we select the image from the gallery and upload. I looked through the samples, but they all also indicate the file name, for example: mnt / sdcard / read.txt. But I want to go only to sdcard so that the user can select their own file, this can be done.

0
source share
1 answer
U can easily do that its very easy

    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccessUpload, fail);

    function onFileSystemSuccessUpload(fileSystem) {
     // get directory entry through root and access all the folders
             var directoryReader = fileSystem.root.createReader();

    // Get a list of all the entries in the directory
    directoryReader.readEntries(successReader,fail); 

          }

      function successReader(entries) {
        var i;
        for (i=0; i<entries.length; i++) {
           //alert(entries[i].name);
           if(entries[i].isDirectory==true)
           {
             var directoryReaderIn = entries[i].createReader();
            directoryReaderIn.readEntries(successReader,fail); 

           }

            if(entries[i].isFile==true)
             {
          entries[i].file(uploadFile, fail);
           }
        }
    }; 

 function uploadFile(file) {
var target=""; //the url to upload on server
     var ft = new FileTransfer(),path = "file://"+ file.fullPath,name = file.name;
                ft.upload(path, target, win, fail, { fileName: name });
               // var ft = new FileTransfer();
              //ft.upload(file.fullPath, target, win, fail, options);


            function win(r) {
                alert("Code = " + r.responseCode);
               alert("Response = " + r.response);
                alert("Sent = " + r.bytesSent);
            }

            function fail(error) {
                alert("An error has occurred: Code = " + error.code);
            }
}
0
source

All Articles