<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN">
<Html>
<Head>
<Title> Untitled </title>
<Script>
Var img = null;
Var maxfilesize = 1048576;
Var filePath;
Function checkimage ()
{
FilePath = document. getElementById ("FILE1"). value; // obtain the content in the upload control.
If (/^. + \. (gif | jpg | png) $/I. test (filePath )){
Img = new Image ();
Img. style. display = 'none ';
Img. attachEvent ("onerror", ErrImgType );
Img. attachEvent ("onreadystatechange", ErrImgBig );
Document. body. insertAdjacentElement ("beforeend", img );
Img. src = filePath;
} Else {ErrImgType ()}
}
Function ErrImgType (){
Upload. reset (); // reset the upload Control
Alert ("the type of uploaded image files can only be jpg, png, or gif! ");
Return false;
}
Function ErrImgBig (){
If (img. fileSize> maxfilesize ){
Upload. reset (); // reset the upload Control
Alert ("the file size cannot exceed 1 MB! ");
Return false;
}
}
</Script>
</Head>
<Body>
<Form method = "post" id = "upload" NAME = "upload" ENCTYPE = "multipart/form-data">
<Input type = "file" id = "FILE1" name = "FILE1" class = "bg4" onChange = "setTimeout ('checkimage () ', 500)">
</Form>
</Body>
</Html>