Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Reading file from javascript [modified]

Reading file from javascript [modified]

Scheduled Pinned Locked Moved Web Development
javascripttutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theprinc
    wrote on last edited by
    #1

    Does anybody know how to read a file using javascript I have tried but it seems not to work fh = fopen("filepath", 0); // Open the file for reading if(fh!=-1) // If the file has been successfully opened { length = flength(fh); // Get the length of the file str = fread(fh, length); // Read in the entire file fclose(fh); // Close the file // Display the contents of the file write(str); } -- modified at 10:48 Monday 10th July, 2006

    P L 2 Replies Last reply
    0
    • T theprinc

      Does anybody know how to read a file using javascript I have tried but it seems not to work fh = fopen("filepath", 0); // Open the file for reading if(fh!=-1) // If the file has been successfully opened { length = flength(fh); // Get the length of the file str = fread(fh, length); // Read in the entire file fclose(fh); // Close the file // Display the contents of the file write(str); } -- modified at 10:48 Monday 10th July, 2006

      P Offline
      P Offline
      Paddy Boyd
      wrote on last edited by
      #2

      If you are running this through a web page you probably won't have permissions to open a client's file system.

      T 1 Reply Last reply
      0
      • P Paddy Boyd

        If you are running this through a web page you probably won't have permissions to open a client's file system.

        T Offline
        T Offline
        theprinc
        wrote on last edited by
        #3

        I have an input element of type file, so i can get the file path on the client side, but i dont know how to read the file on the client's side. Im using Jboss as my container, and im using JSPs. Any help.

        G 1 Reply Last reply
        0
        • T theprinc

          I have an input element of type file, so i can get the file path on the client side, but i dont know how to read the file on the client's side. Im using Jboss as my container, and im using JSPs. Any help.

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          That doesn't work. If you run the Javascript in the browser, you can't access any file system. If you run the Javascript in the server, you can't access the file system of the client, only the server. --- b { font-weight: normal; }

          D 1 Reply Last reply
          0
          • T theprinc

            Does anybody know how to read a file using javascript I have tried but it seems not to work fh = fopen("filepath", 0); // Open the file for reading if(fh!=-1) // If the file has been successfully opened { length = flength(fh); // Get the length of the file str = fread(fh, length); // Read in the entire file fclose(fh); // Close the file // Display the contents of the file write(str); } -- modified at 10:48 Monday 10th July, 2006

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            As far as I am aware, javascript is forbidden access to your file system except by using an Active X control. In which case, taken from an older version of JScript : OpenTextFile Method ============================= var fs, a, ForAppending; ForAppending = 8; fs = new ActiveXObject("Scripting.FileSystemObject"); a = fs.OpenTextFile("c:\\testfile.txt", ForAppending, false); ... a.Close() FileExists method ========================= function ReportFileStatus(filespec) { var fso, s = filespec; fso = new ActiveXObject("Scripting.FileSystemObject"); if (fso.FileExists(filespec)) s += " exists."; else s += " doesn't exist."; return(s); } Write method: ============================= function WriteDemo() { var fso, f, r var ForReading = 1, ForWriting = 2; fso = new ActiveXObject("Scripting.FileSystemObject") f = fso.OpenTextFile("c:\\testfile.txt", ForWriting, true) f.Write("Hello world!"); f.Close(); f = fso.OpenTextFile("c:\\testfile.txt", ForReading); r = f.ReadLine(); return(r); }

            1 Reply Last reply
            0
            • G Guffa

              That doesn't work. If you run the Javascript in the browser, you can't access any file system. If you run the Javascript in the server, you can't access the file system of the client, only the server. --- b { font-weight: normal; }

              D Offline
              D Offline
              dwatkins dirq net
              wrote on last edited by
              #6

              Yeah, you'll have to upload to the server and do something with the file there. You can't use JavaScript to read files on a client machine. I think that Flash might be able to do that.. anyone seen this lately? Dirk Watkins

              L 1 Reply Last reply
              0
              • D dwatkins dirq net

                Yeah, you'll have to upload to the server and do something with the file there. You can't use JavaScript to read files on a client machine. I think that Flash might be able to do that.. anyone seen this lately? Dirk Watkins

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Javascript and VBScript are ONLY able to access files on your hard drive using Active X controls.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups