Home > Web Front-end > JS Tutorial > Using js to get the uploaded file name is purely for beautification_javascript skills

Using js to get the uploaded file name is purely for beautification_javascript skills

WBOY
Release: 2016-05-16 17:19:07
Original
974 people have browsed it

Why use js to get the uploaded file name? In fact, it is purely for beautification and friendliness.

However, it is not like what is circulated on the Internet. Use path.substring(path.lastIndexOf('/') 1);

This is how it works. Many problems will arise from time to time.
For example, the value of the input form in Firefox can obtain the file name by default, while IE displays the file path.

So we need to treat it differently. Under Firefox, lastIndexOf('/') gets -1, but under IE, the directory displays backslashes. Of course, under Linux
, others What the browser obtains is forward slash / (it has not been proven that the value obtained by the browser file under Linux will be the full path);
Using js to get the uploaded file name is purely for beautification_javascript skills
You have to use two judgments:

Copy code The 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);
}
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template