asp.net (VBScript) uploads pictures and generates thumbnails at the same time:
<script language= "VB" runat= "Server" >
Sub UploadFile (sender as Object, E as EventArgs)
If FileUp.PostedFile.ContentLength = 0 Then
Fileinfo.visible = False
Exit Sub
Else
Fileinfo.visible = True
Fdisplay1.visible = True
End If
Fsize.text = "Upload file size" + CSTR (fileup.postedfile.contentlength/1024) + "KB"
Fname.text = "uploaded file name:" +fileup.postedfile.filename+ "<br>" +fname.text
The Write database
On Error Resume Next
Dim myconn As SqlConnection
Dim Mycomm As SqlCommand
Dim sql As String
Dim id As Integer
Dim Image,anewimage as System.Drawing.Image
Dim width,height,newwidth,newheight As Integer
Dim CALLB as System.Drawing.Image.GetThumbnailImageAbort
Myconn=new SqlConnection (ConfigurationSettings.AppSettings ("Database"))
MyConn.Open ()
Sql= "INSERT into the picture (name, class, Introduction, Attributes) VALUES (" "&request.cookies (" Dgxyl "). VALUES (" Dgxylname ") &" "," & Request.Cookies ("Dgxyl"). VALUES ("DGXYLBJ") & "," "&trim (Request (" TextBox1 ")) &", "" &request ("R1") & "") "
Mycomm=new SqlCommand (Sql,myconn)
Mycomm.executenonquery ()
Myconn.close ()
Dim mycommand as New SqlCommand ("Select top 1 IDs from picture order by id Desc", myconn)
MyCommand.Connection.Open ()
Dim myreader as Sqldatareader=mycommand.executereader ()
If Myreader.read () then
Id=myreader ("id")
End If
Myconn.close ()
The Save picture
FileUp.PostedFile.SaveAs (Server.MapPath ("\classpic\") &cstr (ID) & ". jpg")
The build thumbnail
Image=system.drawing.image.fromfile (Server.MapPath ("/classpic/" +cstr (ID) + ". jpg")
Width=image. Width
Height=image.height
If Width>height Then
newwidth=250
Newheight=image.height/image. Width*newwidth
Else
newheight=250
Newwidth=image. Width/image.height*newheight
End If
Response.Write ("id=" +cstr (ID) + "width=" +cstr (width) + "; height=" +cstr (height) + "")
Response.Write ("Newwidth=" +cstr (newwidth) + "newheight=" +cstr (newheight) + "<br>")
Anewimage=image. Getthumbnailimage (Newwidth,newheight,callb,new system.intptr ())
Anewimage.save (Server.MapPath ("/smallpic/" +cstr (ID) + ". jpg")
Image. Dispose ()
Dim Filesplit () as String = Split (FileUp.PostedFile.FileName, "\")
Dim FileName as String = Filesplit (filesplit.length-1)
Dim exts () as String = Split (FileName, ".")
Dim Ext as String = LCase (exts (exts.length-1))
Fdisplay.text = "<a target=" _blank "href="/classpic/"&cstr (ID) &". jpg "&" "> View upload file </A>"
fdisplay1.text= "<a href="/picture/default.asp?bj= &cstr (Request.Cookies ("Dgxyl"). VALUES ("DGXYLBJ")) & "> Return </a>"
End Sub
</script>
<script language=javascript>
<!--
var Requestsubmitted=false;
function Guestbook_validator (theform)
{
Check to see if you are submitting a new
if (requestsubmitted==true) {
Alert ("You have submitted a message, please wait for the server to reply!") ");
return (false);
}
Requestsubmitted=true;
return (true);
}
-->
</SCRIPT>
<Html>
<body bgcolor=white>
<Hr></H3>
<div id= "FileInfo" visible= "False" runat= "Server" >
<asp:label id= "fsize" runat= "Server"/><br>
<asp:label id= "FName" runat= "Server"/><br>
<asp:label id= "Fdisplay" runat= "Server"/>
<asp:label id= "FDisplay1" runat= "Server"/>
</Div>
<form enctype= "Multipart/form-data" onsubmit= "return Guestbook_validator (This)" runat= "Server" >
Uploading files
<input type= "File" id= "Fileup" runat= "Server" size= "><br>"
Picture properties: <input type= "Radio" value= <%=request.cookies ("Dgxyl"). VALUES ("DGXYLBJ")%> "name=" R1 "checked>" <input type= "Radio" value= "The whole School" name= "R1" > School (This class is only shown in this class, the whole school is shown in the whole school) <P>
Picture Description:<br>
<asp:textbox id= "TextBox1" runat= "Server" width= "233px" height= "141px" >
</asp:TextBox>
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server" controltovalidate= "TextBox1" Errormessage= "Please enter picture description" >
</asp:RequiredFieldValidator><br>
<asp:button id= "Upload" onclick= "UploadFile" text= "Upload Picture" runat= "Server"/>
</form>
<Hr>
<p> Note:</p>
<ol>
<li><b> do not upload photos of contaminated environment, otherwise the account will be deleted! </b></li>
<li><font color= "#808000" ><b> please fill in the photo description, the picture description is not detailed will be considered as a random image, will be deleted! </b></font></li>
</ol>
</Body>
</Html>