0

If I try to get a filename value from an HTML input object in IE it returns the full path and filename, but in Chrome it only returns the base filename. Is there a way to make it return the full path and filename regardless of the browser, or do I have to jump over to something like JQuery to do that? God almighty I HATE stupid non-standard web "standards".

Code example:

<input type="file" name="fn" id="fn"/>

Click on the selection button in IE and navigate to a path like "\server123\apps\folder1\setup.exe" and the result that shows in the form, and gets processed in the [submit] handler event, is also "\server123\apps\folder1\setup.exe". However, running the same steps in Chrome 22.x up to 28.x, it only displays "setup.exe" and hands that through the [submit] handler even as well. Is there a way to make it handle the full path and filename regardless of the browser?

Skatterbrainz
  • 1,077
  • 5
  • 23
  • 31

2 Answers2

1

Chrome scrubs out the path information for security reasons. So there is no way to get access to the path information.

fileinput.onchange = function(e) {
  console.log(e.target.value); // Will be c:\fakepath
}
Kinlan
  • 16,315
  • 5
  • 56
  • 88
  • So.... the ONLY way to get the full path is either (a) add JQuery code to the mix (it's currently all ASP, not ASP.NET), or (b) require users to access the page with IE. Is that correct? – Skatterbrainz Jul 24 '13 at 13:05
  • 1
    Chrome will not expose the full path, it will only say fakepath – Kinlan Jul 24 '13 at 13:23
1

I finally worked it out so that the app will detect which browser the user is working with and display an appropriate message when it's not IE. The message simply advises the user to copy and paste the entire UNC path into the comment box. This is entirely an intranet application, so nothing is exposed outside.

Skatterbrainz
  • 1,077
  • 5
  • 23
  • 31