Why use js to get the uploaded file name? In fact, it is purely for beautification and friendliness,
However, this is not the case on the Internet. Use path. substring (path. lastIndexOf ('/') + 1 );
This may cause many problems at work.
For example, the file name can be obtained by default for the value of firefox input form, while ie displays the file path.
In firefox, lastIndexOf ('/') gets-1, while in ie, the directory displays a backslash, \, of course, in Linux
Other browsers get the forward slash (/). For the moment, it is not proved that the file value obtained by a browser in Linux is the full path );
Two judgments are required:
Copy codeThe Code is 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 );
}