当前位置:网站首页>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
边栏推荐
- #yyds干货盘点#stringprep --- 因特网字符串预备
- C1000k TCP connection upper limit test
- 浅谈c语言指针的强制转换
- Accessing private members using templates
- Download xshell 6 and xftp6 official websites
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- ArcMap连接 arcgis server
- FTP、ssh远程访问及控制
- js 计算时间差
- Using bafayun to control the computer
猜你喜欢
为何PostgreSQL即将超越SQL Server?
Eight bit binary multiplier VHDL
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
该买什么设备,Keysight 给你挑好了
Wechat video extraction and receiving file path
Getting started with vcpkg
Keysight has chosen what equipment to buy for you
[记录]TypeError: this.getOptions is not a function
浅谈c语言指针的强制转换
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
随机推荐
浅谈c语言指针的强制转换
How about CICC wealth? Is it safe to open an account up there
Feature selection feature_ selection--SelectKBest
Esp32 (UART ecoh) - serial port echo worm learning (2)
Esp32 (UART event) - serial port event learning (1)
Use of kotlin collaboration in the project
Introduction to ROS learning notes (II)
After opening the original normal project, the dependency package displays red and does not exist.
SSDB foundation 1
Methods of nested recycleview to solve sliding conflict and incomplete item display
openlayers 5.0 热力图
Esp01s with Arduino development environment
Network protocol: SCTP flow control transmission protocol
MySQL statement
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
Click the input box to pop up the keyboard layout and move up
Simple use of navigation in jetpack
SSDB基础
js获取本机ip地址
openlayers draw矩形