当前位置:网站首页>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
边栏推荐
猜你喜欢
Getting started with vcpkg
Switching power supply design sharing and power supply design skills diagram
mysql通过binlog恢复或回滚数据
Introduction to ROS learning notes (II)
Network protocol: SCTP flow control transmission protocol
七、DOM(下) - 章节课后练习题及答案
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
MySQL Téléchargement et installation de la version Linux
One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
2022.04.23 (lc_763_divided into letter interval)
随机推荐
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
[popular science] CRC verification (I) what is CRC verification?
Implementation of TCP UDP communication with golang language
About the operation of unit file reading (I)
Installation, use and problem summary of binlog2sql tool
Esp32 (UART ecoh) - serial port echo worm learning (2)
Circuit on-line simulation
Use bitnami / PostgreSQL repmgr image to quickly set up PostgreSQL ha
中金财富怎么样?在上边开户安全吗
为何PostgreSQL即将超越SQL Server?
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born
How about CICC wealth? Is it safe to open an account up there
剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
Nacos作为服务配置中心实战
Click the input box to pop up the keyboard layout and move up
网络协议之:sctp流控制传输协议
Download xshell 6 and xftp6 official websites
微搭低代码零基础入门课(第三课)
Screenshot using projectmediamanager
mysql_linux版本的下载及安装详解