当前位置:网站首页>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
边栏推荐
- Use of kotlin collaboration in the project
- [play with lighthouse] Tencent cloud lightweight server builds a full platform video analysis video download website
- [advanced level 11 of C language -- character and string functions and their simulation implementation (2)]
- 2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
- 開關電源設計分享及電源設計技巧圖解
- c1000k TCP 连接上限测试1
- 7、 DOM (Part 2) - chapter after class exercises and answers
- Using 8266 as serial port debugging tool
- Installation, use and problem summary of binlog2sql tool
- openlayers 5.0 热力图
猜你喜欢

2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)

mysql通过binlog恢复或回滚数据

C: generic reflection

Esp01s with Arduino development environment

Practice of Druid SQL and security in meituan review

为何PostgreSQL即将超越SQL Server?

FTP、ssh远程访问及控制

MySQL restores or rolls back data through binlog

Introduction to ROS learning notes (I)

MySQL学习第五弹——事务及其操作特性详解
随机推荐
On the forced conversion of C language pointer
Class loading process of JVM
Zlib realizes streaming decompression
Openharmony open source developer growth plan, looking for new open source forces that change the world!
ESP32 LVGL8. 1 - slider slider (slider 22)
The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
mysql_linux版本的下载及安装详解
開關電源設計分享及電源設計技巧圖解
Installation, use and problem summary of binlog2sql tool
: app: transformclasseswithrobustfordevrease meituan hot repair compilation error record
【玩转Lighthouse】腾讯云轻量服务器搭建全平台视频解析视频下载网站
js上传文件时控制文件类型和大小
Some records used by VS2010
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
ESP32 LVGL8. 1 - bar progress bar (bar 21)
2022.04.23(LC_714_买卖股票的最佳时机含手续费)
Modify the font size of hint in editext
static类变量快速入门
SQL Server database in clause and exists clause conversion