read and write local text files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dreamfalcon
    New Member
    • Oct 2007
    • 20

    read and write local text files

    Hi!
    I need to read and write the content of a text file given by the users.

    The idea is to have two options.
    Read:
    -the user selects a file with a <input type="file">
    -using javascript, read the content of the file and process it.

    Write:
    -build a string and display a "Save as dialog" to save to a text file

    I just need it to work in Firefox.
    I´m using mootools if it helps.
    Can anyone help me?

    thx in advance
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    JavaScript can't access the local file system and read/write local files. You will need some server-side code to be able to upload the file and then read/write it.

    Comment

    • dreamfalcon
      New Member
      • Oct 2007
      • 20

      #3
      That's a bummer :(

      But ok, now the question is how to upload using ajax?
      I think I've done it in the pass, but I cant remember how.
      I have to use a iframe !?

      Thx

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Here's one example. It still uses an iframe.

        Comment

        • rnd me
          Recognized Expert Contributor
          • Jun 2007
          • 427

          #5
          Originally posted by dreamfalcon
          Hi!
          I need to read and write the content of a text file given by the users.

          The idea is to have two options.
          Read:
          -the user selects a file with a <input type="file">
          -using javascript, read the content of the file and process it.

          Write:
          -build a string and display a "Save as dialog" to save to a text file

          I just need it to work in Firefox.
          I´m using mootools if it helps.
          Can anyone help me?

          thx in advance
          it will be possible in firefox3.
          look at the changelog for more information.

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by dreamfalcon
            I need to read and write the content of a text file given by the users.

            The idea is to have two options.
            Read:
            -the user selects a file with a <input type="file">
            -using javascript, read the content of the file and process it.

            Write:
            -build a string and display a "Save as dialog" to save to a text file

            I just need it to work in Firefox.
            Looking at this again, maybe XUL will help, e.g. see this link.

            Comment

            • dreamfalcon
              New Member
              • Oct 2007
              • 20

              #7
              Originally posted by acoder
              Looking at this again, maybe XUL will help, e.g. see this link.
              I already tried, gives as error of permission denied in
              "netscape.secur ity.PrivilegeMa nager.enablePri vilege("Univers alXPConnect");"

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Originally posted by dreamfalcon
                I already tried, gives as error of permission denied in
                "netscape.secur ity.PrivilegeMa nager.enablePri vilege("Univers alXPConnect");"
                You may need to change some settings. It works for me (when I allow from the popup warning).

                Comment

                • shahjapan
                  New Member
                  • Apr 2007
                  • 63

                  #9
                  Originally posted by acoder
                  You may need to change some settings. It works for me (when I allow from the popup warning).
                  you can store anything that u want to store using preferences in firefox.

                  Comment

                  • rnd me
                    Recognized Expert Contributor
                    • Jun 2007
                    • 427

                    #10
                    here is a save as routine for you: (ff only)


                    Code:
                    function dataUrlStr(data) {
                        return "data:x-application/plainText," + escape(data); 
                    }
                    window.open(dataUrlStr("hello world"))

                    using an unknown mime causes a save/open prompt.


                    you will likely need a server echo to read the local files.
                    in asp3 it would be something like

                    Code:
                    response.binaryWrite(request.binaryRead)

                    Comment

                    • rnd me
                      Recognized Expert Contributor
                      • Jun 2007
                      • 427

                      #11
                      Originally posted by shahjapan
                      you can store anything that u want to store using preferences in firefox.

                      what preferences are you referring to? i couldn't find anything, but i would love to be able to save as described.

                      Comment

                      Working...