Why to use JS to get uploaded file name? In fact, purely to beautify, friendly,
However, it is not the same as the Internet, using path.substring (Path.lastindexof ('/') +1);
There are a lot of problems in this kind of work.
For example, the value value of the Firefox input form can be obtained by default, while IE displays the file path.
So to differentiate, under Firefox lastindexof ('/') get is-1, and in IE, the directory shows is a backslash, \, of course, in Linux
, the other browsers get a forward slash/(it is not yet proven that the value obtained by the browser file under Linux will be a full path);
It takes two times to judge:
Copy Code code as follows:
function GetFileName (path) {
var pos1 = path.lastindexof ('/');
var pos2 = path.lastindexof (' \ \ ');
var pos = Math.max (POS1, Pos2)
if (pos<0)
return path;
Else
Return path.substring (pos+1);
}