Use JS to get uploaded file name, not circulated online, with 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:
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);
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.