js method to verify uploaded images_javascript skills
The example in this article describes the js method of verifying uploaded images. Share it with everyone for your reference. The specific implementation method is as follows:
<!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=utf-8" /> <title>js验证图片</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>
I hope this article will be helpful to everyone’s JavaScript programming design.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

We usually receive PDF files from the government or other agencies, some with digital signatures. After verifying the signature, we see the SignatureValid message and a green check mark. If the signature is not verified, the validity is unknown. Verifying signatures is important, let’s see how to do it in PDF. How to Verify Signatures in PDF Verifying signatures in PDF format makes it more trustworthy and the document more likely to be accepted. You can verify signatures in PDF documents in the following ways. Open the PDF in Adobe Reader Right-click the signature and select Show Signature Properties Click the Show Signer Certificate button Add the signature to the Trusted Certificates list from the Trust tab Click Verify Signature to complete the verification Let

1. After opening WeChat, click the search icon, enter WeChat team, and click the service below to enter. 2. After entering, click the self-service tool option in the lower left corner. 3. After clicking, in the options above, click the option of unblocking/appealing for auxiliary verification.

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

PHP8 is the latest version of PHP, bringing more convenience and functionality to programmers. This version has a special focus on security and performance, and one of the noteworthy new features is the addition of verification and signing capabilities. In this article, we'll take a closer look at these new features and their uses. Verification and signing are very important security concepts in computer science. They are often used to ensure that the data transmitted is complete and authentic. Verification and signatures become even more important when dealing with online transactions and sensitive information because if someone is able to tamper with the data, it could potentially

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese
