当前位置:网站首页>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
边栏推荐
- SSDB基础
- std::stoi stol stoul stoll stof stod
- RPM包管理
- ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- 微搭低代码零基础入门课(第三课)
- Use of kotlin collaboration in the project
- SSDB基础2
- Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
- Deeply understand what new and make in golang are and what are the differences?
猜你喜欢

mysql_linux版本的下载及安装详解

Summary of actual business optimization scheme - main directory - continuous update

7、 DOM (Part 2) - chapter after class exercises and answers

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

为何PostgreSQL即将超越SQL Server?

Class loading process of JVM

Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha

Druid SQL和Security在美团点评的实践

ESP32 LVGL8. 1 - calendar (calendar 25)

The difference between ordinary inner class and static inner class
随机推荐
[play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
SQL常用的命令
Sentinel规则持久化进Nacos
MVVM模型
Go language GUI framework Fyne Chinese garbled or not displayed
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
Simple use of viewbinding
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
Raspberry pie 18b20 temperature
C1000k TCP connection upper limit test 1
Wechat video extraction and receiving file path
网络协议之:sctp流控制传输协议
Introduction to ROS learning notes (I)
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
MySQL学习第五弹——事务及其操作特性详解
Eight bit binary multiplier VHDL
2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
Sword finger offer II 116 Number of provinces - spatial complexity O (n), time complexity O (n)
MySQL statement