JS jquery upload file format size judgment Simple summary

Source: Internet
Author: User
Tags rar

Hello, everyone. I am the moon in front of the bed, suspicion is ground frost

Html

<a href= "javascript:;" class= "file" > Add attachment
<input type= "File" Name= "id=" fileId "onchange=" Upload () ">
</a>
/** determine the file format of the uploaded file **/
var filePath = "";
var fileType = "";
function upload () {
var fileName = $ (' #fileId '). Val (). split (' \ \ '); Get an array of file names
var fileSize = document.getElementById (' fileId '). Files[0];//get file size;
FileName2 = Filename[filename.length-1]; Get file name
FilePath = $ (' #fileId '). Val (). toLowerCase (). Split (".");
FileType = filepath[filepath.length-1];//Get End-of-file type such as zip rar This writing ensures that it is the last
$ ('. Errhint '). Show (). Text (filename[2]);
Console.log (FilePath);
Console.log (FileType);
if (! ( FileType = = "PNG" | | FileType = = "JPG" | | FileType = = "Xlsx" | | FileType = = "Docx" | | FileType = = "rar" | | FileType = = "Zip")) {
$ ('. Errhint '). Show (). Text (' file format does not meet the requirements! ‘)
}else if (filesize.size>10485760) {
$ ('. Errhint '). Show (). Text (' Error! Please upload no more than 10M files ');
Return
}
}
Copies can be used directly

JS jquery upload file format size judgment Simple summary

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.