Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  14] [ 7]  / answers: 1 / hits: 153428  / 13 Years ago, fri, december 23, 2011, 12:00:00

I need to show the name of the currently selected file (in <input type=file> element).



Everything is fine, the only problem is I'm getting this kind of string C:fakepath
typog_rules.pdf (browset automatically puts this as value for the input element).



When I try to split the string by '' or '\' it fails because of unescaped slashes. Attempts to match/replace slashes fails too. Is there a way around this? I need this to work at least in Opera and IE (because in other browsers I can use FileReader)



E.G. I'm getting C:fakepathtypog_rules.pdf as input and want to get typog_rules.pdf as output.


More From » file

 Answers
38

For security reasons, it is not possible to get the real, full path of a file, referred through an <input type=file /> element.



This question already mentions, and links to other Stack Overflow questions regarding this topic.




Previous answer, kept as a reference for future visitors who reach this page through the title, tags and question.

The backslash has to be escaped.



string = string.split(\);


In JavaScript, the backslash is used to escape special characters, such as newlines (n). If you want to use a literal backslash, a double backslash has to be used.



So, if you want to match two backslashes, four backslashes has to be used. For example,alert(\\) will show a dialog containing two backslashes.


[#88404] Wednesday, December 21, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
loganl

Total Points: 424
Total Questions: 86
Total Answers: 112

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;