1. client-side Verification
- <Script language = "javascript">
- Img = new Image ();
- Function Check_FileTypeAndFileSize ()
- {
- // Obtain the upload path
- Var str = document. all. uploadFile. value;
- // Verify that the upload path is not empty
- If (str = "")
- {
- Alert ("select the image to upload first! ");
- Return false;
- }
- // Verify that the format of the uploaded file is correct
- Var pos = str. lastIndexOf (".");
- Var lastname = str. substring (pos, str. length)
- If (lastname. toLowerCase ()! = ". Jpg" & lastname. toLowerCase ()! = ". Gif ")
- {
- Alert ("the file type you uploaded is" lastname ", and the image must be JPG or GIF ");
- Return false;
- }
- // Verify the width and height of the uploaded file
- If (img. width/img. height & gt; 1.6)
- {
- Return confirm (the image you uploaded is larger than. Are you sure you want to upload it ?);
- }
- // Verify whether the size of the uploaded file has exceeded
- If (img. fileSize/1024> 150)
- {
- Alert ("the size of the file you uploaded exceeds the limit of KB! ");
- Return false;
- }
- Return true;
- }
- // Upload the file box address change event to preview the image instantly
- Function changephoto ()
- {
- Img. src = document. all. uploadFile. value;
- }
- // -->
- </Script>
- <Div>
- <Upload: InputFile ID = "uploadFile" name = "UploadFilePath" runat = "server" onchange = "changephoto ()"/>
- <Asp: Button ID = "btnUpload" runat = "server" Text = "Upload" OnClientClick = "return Check_FileTypeAndFileSize ()"
- OnClick = "btnUpload_Click"/>
- </Div>
- <Div class = "upload">
- </Div>