Why use js to get the uploaded file name? It’s just for beautification, for friendliness,
However, instead of using path. Substring (path. LastIndexOf (’/’)+1);
There are a lot of problems with this model when it works. For example, the value of the input form in firefox gets the file name by default, while ie displays the file path.
So make a distinction: in firefox, lastIndexOf(’/’) gets -1, whereas in ie, the directory shows a backslash, \, and of course on Linux Next, the forward slash/is obtained by other browsers (it has not been proved yet that the value obtained by browser file under Linux will be the full path); It has to be judged twice:
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);
}