0

There are many similar questions to this, however, when I used the code provided, it didn't work. My code is as follows:

  function write(fs) {
    fs.root.getFile('archive.txt', {create: true}, function(fileEntry) {
      // Create a FileWriter object for our FileEntry (log.txt).
      fileEntry.createWriter(function(fileWriter) {
        fileWriter.onwriteend = function(e) {
          console.log('Write completed.');
        };
        fileWriter.onerror = function(e) {
          console.log('Write failed: ' + e.toString());
        };
        var blob = new Blob([prompt("MESSAGE: ")], {type: 'text/plain'});
        fileWrite.write(blob);
      }, errorHandler);
    }, errorHandler);
  }
  function onInitFs(fs) {
    fs.root.getFile('archive.txt', {}, function(fileEntry) {
      // Get a File object representing the file,
      // then use FileReader to read its contents.
      fileEntry.file(function(file) {
         var reader = new FileReader();
         reader.onloadend = function(e) {
           var txtArea = document.createElement('textarea');
           txtArea.value = this.result;
           document.body.appendChild(txtArea);
         };
         reader.readAsText(file);
      }, errorHandler);
    }, errorHandler);
  }
  window.requestFileSystem(window.TEMPORARY, 5*1024*1024 /*5MB*/, onInitFs, errorHandler);

The file archive.txt does exist but when I call the function, it doesn't work. So instead I used window.requestFileSystem() which I found on a website. However, when I compile this code through Github, it doesn't work.

Also, if someone could tell me a way to read and write to a file without using php as this is all in html file using Github without git. I have another file in Github in the same directory as this. Would I need to include the full directory rather than archive.txt?

1
  • Maybe you should be clear whehter the javascripts are executed in server (using nodejs, something similar to php because they are not static) or in client (browser). If in browser, you are not reading a file but requesting a file from the server (through url). Commented Mar 23, 2017 at 6:07

1 Answer 1

0

It's not possible without server side code.

I've asked a similar question a while ago.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.