Do not change the security level, before uploading, in the client to determine the size of the picture file
Source: Internet
Author: User
Security | client | upload
Tips collected earlier in the project have recently been used and may be helpful to everyone.
<!--excerpted from 51js-->
<script>
var img=null;
function S ()
{
if (IMG) Img.removenode (TRUE);
Img=document.createelement ("img");
img.style.position= "Absolute";
Img.style.visibility= "hidden";
img.width = 0;
img.height = 0;
Img.attachevent ("onReadyStateChange", ORSC);
Img.attachevent ("onerror", OE);
Document.body.insertAdjacentElement ("BeforeEnd", IMG);
Img.src=inp.value;
}
function OE ()
{
alert ("Cant load img");
}
function ORSC ()
{
if (img.readystate!= "complete") return false;
Alert ("Picture size:" +img.offsetwidth+ "X" +img.offsetheight);
Alert ("Picture size:" +img.filesize);
Btn.disabled=false;
}
</script>
<input id=inp type= "File" >
<br>
<button >test</button><button id=btn disabled>upload</button>
As you can see, it's also very simple, it first defines an IMG object in memory and then uses this object to get the various properties of the IMG object on the client.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service