Open and process a local textfile from javascript

Discussion in 'JavaScript' started by Mannberg, Aug 11, 2010.

  1. #1
    Hi,

    Is it possible to open a local file on the client side from a file chooser and then process/parse that file and display it using javascript? Anyone got a link to a tutorial on this subject?
     
    Mannberg, Aug 11, 2010 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    It's not possible for javascript to work with the contents of files, or obtain the complete path to the file on the local computer in modern browsers. The user must explicitly select a file and send the file to a server, where the server is able to work with the contents of the file.

    A few years ago it was possible to obtain the path to a file the user selected and do things like display their images in a javascript application, but modern browsers do not make more than the filename without the path (ie "file.txt" instead of "c:\path-to\file.txt") available to either javascript in the browser, or the details about the file sent to the server. So if you see something that says it's possible, don't get your hopes up because what you're seeing is outdated information.

    I agree, it sucks. I believe browsers should pop up a permission box when a website wants to access the contents of a file selected using a file chooser. Browser makers are paranoid people though, they tend to side with security over efficiency these days.
     
    joebert, Aug 11, 2010 IP