This content has been marked as final. Show 5 replies
Hope this helps
Hi Doug Gault,
The snippet you provide works fine in Firefix but is not working in IE. When I load this page in IE, even after going through the snippet, the entire file path is present in the variable and hence an alert appears that the file name is more than 70 characters. Any suggestion as to why this is happening?
The issue is that this code
has the wrong path separator for Windows. Use backslash instead:
// Now create an array that contains the individual pieces of // the file name split on the "/" boundaries var myArray = fileName.split('/');
// Now create an array that contains the individual pieces of // the file name split on the "\" boundaries var myArray = fileName.split('\\');
However, also be aware that for security/privacy reasons recent versions of browsers do not expose the file path via the .value method. Firefox, Safari and Chrome only provide the filename. IE6 & IE7 yield the path in Windows format. IE8 and Opera, in an effort not to "break the web" (i.e. to bend over backwards to keep poorly coded and non-interoperable Windows sites working) have adopted an irritating approach of replacing the path with a wholly imaginary "C:\fakepath\".
So your validation may have to cope with up to 3 scenarios, depending on the browsers that need to be supported: only get the filename (FF/Safari/Chrome); get the full path (IE6/7/8 in some security configurations/older versions of all browsers); get a fake path (Opera/IE8 in other security configurations).
For more information see:
(In 2009 MS are still concerned that pathname segments are limited to 8 characters?)