当前位置:网站首页>js上传文件时控制文件类型和大小
js上传文件时控制文件类型和大小
2022-04-23 19:08:00 【Gis烤羊腿真好吃】
/*控制文件类型和大小 e是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: "不接受此文件类型",
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: "附件不存在,请重新输入!",
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: "附件大小不能大于"+filemaxsize/1024+"M!",
type: 'warning'
})
target.value ="";
return false;
}
if(size<=0){
Message({
showClose: true,
message: "附件大小不能为0M!",
type: 'warning'
})
target.value ="";
return false;
}
}在这里插入代码片
版权声明
本文为[Gis烤羊腿真好吃]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_38190600/article/details/102488271
边栏推荐
- Esp32 (UART 485 communication) - 485 communication of serial port (3)
- How can programmers quickly develop high-quality code?
- SSDB基础1
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- SSDB foundation 1
- [today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
- 从技术体系到商业洞察,中小研发团队架构实践之收尾篇
- ESP32 LVGL8. 1 - slider slider (slider 22)
- The type initializer for ‘Gdip‘ threw an exception
- Actual combat of Nacos as service configuration center
猜你喜欢

mysql通过binlog恢复或回滚数据

MySQL学习第五弹——事务及其操作特性详解

The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics

Simplified path (force buckle 71)

开关电源设计分享及电源设计技巧图解

redis优化系列(三)解决主从配置后的常见问题

On the forced conversion of C language pointer

Switching power supply design sharing and power supply design skills diagram

Esp32 (UART ecoh) - serial port echo worm learning (2)

SQL常用的命令
随机推荐
redis优化系列(三)解决主从配置后的常见问题
Advanced transfer learning
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système
该买什么设备,Keysight 给你挑好了
MySQL学习第五弹——事务及其操作特性详解
SSDB Foundation
七、DOM(下) - 章节课后练习题及答案
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
Wechat video extraction and receiving file path
Getting started with vcpkg
2022.04.23(LC_763_划分字母区间)
C1000k TCP connection upper limit test 1
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
Eight bit binary multiplier VHDL
Is it safe to open an account in Bohai futures.
c1000k TCP 连接上限测试
开关电源设计分享及电源设计技巧图解
Nacos作为服务配置中心实战
Switching power supply design sharing and power supply design skills diagram