JavaScript client determines file type and size

Source: Internet
Author: User

<title> submersible non-clogging sewage pump </title>

<meta http-equiv= "Content-type" content= "text/html;charset=gb2312" >
<body>
The following is an example of a client controlling file upload image type and size (note: Because it is a client limit, users can bypass this limitation):
<script language= "JavaScript" >
<!--
var filemaxsize = 50;//Limit uploaded file size, Unit K
function Chkform () {
if (document. hwform.photo.value== "") {alert ("Please select picture! ");d ocument. HwForm.Photo.focus (); return false;}
if (document. hwform.photofilesize.value<=0) {alert ("Please re-select the picture!) ");d ocument. HwForm.Photo.focus (); return false;}
if (document. hwform.photofilesize.value>filemaxsize*1024) {alert ("Picture cannot exceed" +filemaxsize+ "K, please re-select!) ");d ocument. HwForm.Photo.focus (); return false;}
Alert ("Picture type and size is correct, can be submitted! "); return false;
}
-
</script>
<form method= "POST" name= "Hwform" onsubmit= "Return (Chkform ())" enctype= "Multipart/form-data" >
Please select a picture within 50K: <input type= "file" name= "photo" onpropertychange= "if (document. Hwform.photo.value!= ') {document.getElementById (' photoimg '). Src=document. HwForm.Photo.value;} " ><input size= "3" type= "hidden" name= "Photofilesize" value= "1" >
<input type= "Submit" value= "Submission" > <input type= "reset" value= "reset" >
</form>
</body>

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.