Intercepting the uploaded file path

Source: Internet
Author: User

function LastName () {
Get the file path you want to upload
var filepath = document.getElementById ("File1"). Value;
To avoid the problem of escaping the backslash, it will be converted
var re =/(\\+)/g;
var filename=filepath.replace (Re, "#");
Clipping a path string
var one=filename.split ("#");
Gets the last, or file name, of the array
var two=one[one.length-1];
Then intercept the file name to get the suffix name
var three=two.split (".");
Gets the last string intercepted, which is the suffix name
var last=three[three.length-1];
Add the type of suffix you want to determine
var tp = "Jpg,gif,bmp,jpg,gif,bmp";
Returns the position of a qualified suffix name in a string
var rs=tp.indexof (last);
If the returned result is greater than or equal to 0, the description contains the file types that are allowed to upload
if (rs>=0) {
return true;
}else{
Alert ("The upload file you selected is not a valid picture file! ");
return false;
}
}

--From the network

Intercepting the uploaded file path

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.