javascripthtmlfile-access

Absolute path to a local file in the user computer


Is there local file manipulation that's been done with JavaScript that can actually get the absolute path to a file or folder when the user chooses with a directory or file picker?

Specifically, I'd like to read/show the ABSOLUTE PATH from a file and open the file if the user requests it. At this point I'm not worried about gaining permissions and am just assuming I already have full permissions to these files.


Solution

  • Not from the web browser, a website/app in a browser doesn't know much about the hosts it's hitting besides what the host/webserver tells it. You would have to build the path in the web server code and stick that into the site. If the files being served aren't somewhere under the web server root (like /var/www, or the project directory for something like a Python or Node server, etc.), it's considered unsafe to allow access to other paths, which is why paths absolute from the web server root are common, rather than absolute in terms of the host's storage.