惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - ㊣鑫哥

jQuery插件---获取URL参数. 利用反射,泛型,扩展方法快速获取表单值到实体类 [原创]jQuery PreviewImg 上传预览插件 js操作frameset frame 对象 关于“Internet Explorer无法打开站点,已终止操作” JavaScript 面向对象程序设计(下)——继承与多态 JavaScript 面向对象程序设计(上)——封装[转] .net 2.0 制作 柱状图 [转]AJAX之旅 由prototype_1.3.1进入javascript殿堂-类的初探 asp.net如何获取客户端网卡mac地址 [转]不可多得的Javascript(AJAX)开发工具 - Aptana 探究 Singleton 设计模式(构建分布式应用程序) .Net平台下开发中文语音应用程序[转] [转]在自定义Server Control中捆绑JS文件 Step by Step IE下JavaScript迁移到FireFox下的工作笔记[转] Asp.net组件开发(资料贴) 有关于JSON的一些资料 这样的UpdatePanel控件要怎么做 [转]30岁前男人应该做的16件事
JS类 检测上传图片的大小,宽,高及格式检查
㊣鑫哥 · 2007-11-27 · via 博客园 - ㊣鑫哥

下载源程序:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>

 UpLoadFileCheck=function()
 {  
   this.AllowExt=".jpg,.gif";//允许上传的文件类型 0为无限制 每个扩展名后边要加一个"," 小写字母表示
   this.AllowImgFileSize=0;//允许上传文件的大小 0为无限制 单位:KB
   this.AllowImgWidth=0;//允许上传的图片的宽度 0为无限制 单位:px(像素)
   this.AllowImgHeight=0;//允许上传的图片的高度 0为无限制 单位:px(像素)
   this.ImgObj=new Image();
   this.ImgFileSize=0;
   this.ImgWidth=0;
   this.ImgHeight=0;
   this.FileExt="";
   this.ErrMsg="";
   this.IsImg=false;//全局变量
    
 }
 
 UpLoadFileCheck.prototype.CheckExt=function(obj)
 {
  this.ErrMsg="";
  this.ImgObj.src=obj.value;
  //this.HasChecked=false;  
  if(obj.value=="")
  {
   this.ErrMsg="\n请选择一个文件";    
  }
  else
  {   
   this.FileExt=obj.value.substr(obj.value.lastIndexOf(".")).toLowerCase();
   if(this.AllowExt!=0&&this.AllowExt.indexOf(this.FileExt)==-1)//判断文件类型是否允许上传
   {
    this.ErrMsg="\n该文件类型不允许上传。请上传 "+this.AllowExt+" 类型的文件,当前文件类型为"+this.FileExt;   
   }
  }
  if(this.ErrMsg!="")
  {
   this.ShowMsg(this.ErrMsg,false);
   return false;
  }
  else   
   return this.CheckProperty(obj);    
 }
 
 UpLoadFileCheck.prototype.CheckProperty=function(obj)
 {
  if(this.ImgObj.readyState!="complete")//
   {
    sleep(1000);//一秒使用图能完全加载    
   }   
   
  if(this.IsImg==true)
  {
   this.ImgWidth=this.ImgObj.width;//取得图片的宽度
   this.ImgHeight=this.ImgObj.height;//取得图片的高度
   if(this.AllowImgWidth!=0&&this.AllowImgWidth<this.ImgWidth)
   this.ErrMsg=this.ErrMsg+"\n图片宽度超过限制。请上传宽度小于"+this.AllowImgWidth+"px的文件,当前图片宽度为"+this.ImgWidth+"px";
 
   if(this.AllowImgHeight!=0&&this.AllowImgHeight<this.ImgHeight)
   this.ErrMsg=this.ErrMsg+"\n图片高度超过限制。请上传高度小于"+this.AllowImgHeight+"px的文件,当前图片高度为"+this.ImgHeight+"px"; 
  }
 
  this.ImgFileSize=Math.round(this.ImgObj.fileSize/1024*100)/100;//取得图片文件的大小  
  if(this.AllowImgFileSize!=0&&this.AllowImgFileSize<this.ImgFileSize)
   this.ErrMsg=this.ErrMsg+"\n文件大小超过限制。请上传小于"+this.AllowImgFileSize+"KB的文件,当前文件大小为"+this.ImgFileSize+"KB";
 
  if(this.ErrMsg!="")
  {
   this.ShowMsg(this.ErrMsg,false);
   return false;
  }
  else
   return true;
 } 
 
 UpLoadFileCheck.prototype.ShowMsg=function(msg,tf)//显示提示信息 tf=false 显示错误信息 msg-信息内容
 {
  /*msg=msg.replace("\n","<li>");
  msg=msg.replace(/\n/gi,"<li>");
   */
  alert(msg);
 }
 function   sleep(num)  
   {  
    var   tempDate=new   Date();  
    var   tempStr="";  
    var   theXmlHttp   =   new   ActiveXObject(   "Microsoft.XMLHTTP"   );  
    while((new   Date()-tempDate)<num   )  
    {  
    tempStr+="\n"+(new   Date()-tempDate);  
    try{  
    theXmlHttp   .open(   "get",   "about:blank?JK="+Math.random(),   false   );  
    theXmlHttp   .send();  
    }  
    catch(e){;}  
    }  
   //containerDiv.innerText=tempStr;  
   return;  
   }  

 function c(obj)
 {
  var d=new UpLoadFileCheck();
  d.IsImg=true;
  d.AllowImgFileSize=100;
  d.CheckExt(obj)
 }
</script>

</head>

<body>
<input name="" type="file"   onchange="c(this)"/>


</body>下载源程序:
</html>