不改安全级别,上传前,在客户端判断图片文件大小
1 <!--摘自51js-->
2
3 <script>
4 var img=null;
5 function s()
6 {
7 if(img)img.removeNode(true);
8 img=document.createElement("img");
9 img.style.position="absolute";
10 img.style.visibility="hidden";
11 img.width = 0;
12 img.height = 0;
13 img.attachEvent("onreadystatechange",orsc);
14 img.attachEvent("onerror",oe);
15 document.body.insertAdjacentElement("beforeend",img);
16 img.src=inp.value;
17 }
18 function oe()
19 {
20 alert("cant load img");
21 }
22 function orsc()
23 {
24 if(img.readyState!="complete")return false;
25 alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
26 alert("图片尺寸:"+img.fileSize);
27 btn.disabled=false;
28 }
29 </script>
30 <input id=inp type="file">
31 <br>
32 <button onclick="s()">Test</button><button id=btn disabled>UpLoad</button>
2
3 <script>
4 var img=null;
5 function s()
6 {
7 if(img)img.removeNode(true);
8 img=document.createElement("img");
9 img.style.position="absolute";
10 img.style.visibility="hidden";
11 img.width = 0;
12 img.height = 0;
13 img.attachEvent("onreadystatechange",orsc);
14 img.attachEvent("onerror",oe);
15 document.body.insertAdjacentElement("beforeend",img);
16 img.src=inp.value;
17 }
18 function oe()
19 {
20 alert("cant load img");
21 }
22 function orsc()
23 {
24 if(img.readyState!="complete")return false;
25 alert("图片大小:"+img.offsetWidth+"X"+img.offsetHeight);
26 alert("图片尺寸:"+img.fileSize);
27 btn.disabled=false;
28 }
29 </script>
30 <input id=inp type="file">
31 <br>
32 <button onclick="s()">Test</button><button id=btn disabled>UpLoad</button>
浙公网安备 33010602011771号