当前位置:网站首页>JS controls the file type and size when uploading files
JS controls the file type and size when uploading files
2022-04-23 19:09:00 【GIS roast lamb leg is delicious】
/* Control file type and size e yes document*/
ConSizeType(e,[".jpg",".png",".jpeg",".JPG",".PNG",".JPEG",".pdf",".PDF",".doc"])
static ConSizeType(e,TYPE){
console.log(e.target)
var target=e.target
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
var fileSize = 0;
var filetypes =TYPE;
var filepath = target.value;
var filemaxsize = 1024*10;//10M
if(filepath){
var isnext = false;
var fileend = filepath.substring(filepath.lastIndexOf("."));
if(filetypes && filetypes.length>0){
for(var i =0; i<filetypes.length;i++){
if(filetypes[i]==fileend){
isnext = true;
break;
}
}
}
if(!isnext){
Message({
showClose: true,
message: " This file type is not accepted ",
type: 'warning'
})
target.value ="";
return false;
}
}else{
return false;
}
if (isIE && !target.files) {
var filePath = target.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
if(!fileSystem.FileExists(filePath)){
Message({
showClose: true,
message: " The attachment does not exist , Please re-enter !",
type: 'warning'
})
return false;
}
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
} else {
fileSize = target.files[0].size;
}
var size = fileSize / 1024;
if(size>filemaxsize){
Message({
showClose: true,
message: " Attachment size cannot be larger than "+filemaxsize/1024+"M!",
type: 'warning'
})
target.value ="";
return false;
}
if(size<=0){
Message({
showClose: true,
message: " Attachment size cannot be 0M!",
type: 'warning'
})
target.value ="";
return false;
}
} Insert a code chip here
版权声明
本文为[GIS roast lamb leg is delicious]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231908120835.html
边栏推荐
猜你喜欢
ESP32 LVGL8. 1 - checkbox (checkbox 23)
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
Esp01s with Arduino development environment
binlog2sql 工具安装使用及问题汇总
MVVM model
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
12个例子夯实promise基础
ESP32 LVGL8. 1 - roller rolling (roller 24)
随机推荐
Codeforces Round #784 (Div. 4)
Xlslib use
openlayers 5.0 离散聚合点
Esp32 (UART event) - serial port event learning (1)
SSDB foundation 3
MySQL restores or rolls back data through binlog
[记录]TypeError: this.getOptions is not a function
浅谈c语言指针的强制转换
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
After opening the original normal project, the dependency package displays red and does not exist.
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
How about CICC wealth? Is it safe to open an account up there
js 计算时间差
arcMap 发布切片服务
C: generic reflection
Simple use of viewbinding
MVVM model
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
Transaction processing of SQL Server database
Android Development: the client obtains the latest value in the database in real time and displays it on the interface