ASP.NET upload images and generate thumbnails at the same time
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 "
" fname.text
'Write into the database
ON Error ResMe 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))
myconn.open ()
SQL = "INSERT INTO PICTURE" VALUES ("DGXylname"). Values ("DGXYLNAME"). Values ("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 ID from Picture ORDER BY ID DESC", MyConn
mycommand.connection.open ()
DIM MyReader as SqldataReader = MyCommand.executeRead ()
IF myreader.read () THEN
ID = MyReader ("id")
END IF
myconn.close ()
'save Picture
Fileup.postedFile.saveas (Server.MAppath ("/ ClassPIC /") & CSTR (ID) & ". JPG")
'Generate thumbnails
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 =" "; newheight =" cstr (newheight) "
")
AnewImage = image.getthumbnailimage (NewWidth, NewHeight, Callb, New System.Intptr ())
ANEWIMAGE.SAVE (Server.mAppath ("/ smallpic /" cstr (id) "))
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 = " return "
End Sub
script>
Var RequestSubmitted = false;
Function Guestbook_validator (Theform)
{
/ / Check if you submit it from the new
IF (RequestSubmitted == True) {
Alert ("You have already submitted message, please wait for the server to answer!");
Return (False);
}
REQUESTSUBMITTED = TRUE;
Return (TRUE);
}
// ->
Script>
Div>