First, client-side mode validation
Copy Code code as follows:
<script language= "JavaScript" >
Img=new Image ();
function Check_filetypeandfilesize ()
{
Get Upload Path
var Str=document.all.uploadfile.value;
Verify that the upload path is not empty
if (str== "")
{
Alert ("Please select the picture you want to upload first!") ");
return false;
}
Verify that the upload file is in the correct format
var pos = Str.lastindexof (".");
var LastName = str.substring (pos,str.length)
if (Lastname.tolowercase ()!= ". jpg" && lastname.tolowercase ()!= ". gif")
{
Alert ("You upload a file type of" LastName ", the picture must be JPG, GIF type");
return false;
}
Verify that the upload file has a wide and high ratio
if (img.width/img.height>1.6)
{
return confirm (you upload more than 8:5 of the picture, confirm to upload it?) );
}
Verify that the upload file is out of size
if (img.filesize/1024>150)
{
Alert ("The size of the file you uploaded exceeds the 150K limit!") ");
return false;
}
return true;
}
Upload file Box Address Change event, instant preview picture
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>