1

We are building a web application to help people organize their local files; it has a text input field in HTML5/JS.

Ideal functionality: user clicks on the text box and it lets them select a file or folder on their local drive, which passes the path of said file or folder to our server.

Is there a JS API or HTML5 method to find a path to a local file and folder?

fox
  • 15,428
  • 20
  • 55
  • 85
  • I've gotta be honest, HTML and JS is going to get you nowhere in terms of a browser-based file management system. Browser security is going to be a huge hurdle for you. You would have to combine it with another technology: Flash, Java, Silverlight, or something that can ask you to trust it; even then you're going to find your project difficult. – Cᴏʀʏ Sep 28 '12 at 04:47

1 Answers1

2

Due to browser security, you cannot get the file location from a FILE input. For that same reason, you will notice that FILE inputs always get reset to blank after a postback. This is because the browser will not persist or expose the file path as a security measure.

Ryan Wheale
  • 26,022
  • 8
  • 76
  • 96
  • Also: the only information you can get from a file input is the file name. It doesn't expose the full path to the file. – Cᴏʀʏ Sep 28 '12 at 04:42
  • Is there a way to get just the file or folder name? We currently are thinking about partitioning the path out separately, but it would be nice if the user could select individual files from within the path to include. – fox Sep 28 '12 at 04:45
  • As Cory pointed out, you will have access to the filename, but that's it. You can't even get then name of the parent directory. You could possibly find a Java applet to allow for the functionality you want, but nothing native in the browser. – Ryan Wheale Sep 28 '12 at 04:55
  • @RyanWheale Java applets are no longer supported in most browsers, but it is still possible to do this using the [File System Access API](https://stackoverflow.com/a/51150691/975097), in browsers that support it. – Anderson Green Feb 23 '22 at 21:24