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