Last post Nov 07, 2005 06:38 AM by zioturo
Nov 05, 2004 08:01 PM|Shadam|LINK
<script runat="server"> Dim uploadSucess As Boolean Dim strFileName As String Dim filepath as String Sub btnUpload_Click(sender As Object, e As EventArgs) uploadSucess = uploadMainImage() If (uploadSucess)
Then generateThumbnail() End If End Sub Function UploadMainImage() 'Check to make sure we actually have a file to upload If Not (fileupload1.PostedFile Is Nothing) Then Dim strLongFilePath As String = fileupload1.PostedFile.FileName Dim intFileNameLength As
Integer = InStr(1, StrReverse(strLongFilePath), "\") strFileName = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2) Select Case fileupload1.PostedFile.ContentType 'Make sure we are getting a valid JPG image Case "image/pjpeg", "image/jpeg"
filepath = Server.MapPath("\") & "\uploaded_images\" fileupload1.PostedFile.SaveAs(filepath & strFileName) Return True Case Else 'Not a valid jpeg image lblMsg.Text = "Not a valid jpeg image" Return False End Select End If End Function Function generateThumbnail()
'Create a new Bitmap Image loading from location of origional file Dim bm as Bitmap = System.Drawing.Image.FromFile(filePath & strFileName) 'Declare Thumbnails Height and Width Dim newWidth as Integer = 300 Dim newHeight as Integer = (newWidth/bm.width)*bm.Height
'Create the new image as a blank bitmap Dim resized as Bitmap = new Bitmap(newWidth,newHeight) 'Create a new graphics object with the contents of the origional image Dim g as Graphics = Graphics.FromImage(resized) 'Resize graphics object to fit onto the resized
image g.DrawImage(bm, new Rectangle(0,0,resized.Width,resized.Height),0,0,bm.Width,bm.Height,GraphicsUnit.Pixel) 'Get rid of the evidence g.Dispose() 'Create new path and filename for the resized image Dim newStrFileName as String = FilePath & "T_" & strFileName
'Save the new image to the same folder as the origional resized.Save(newStrFileName,ImageFormat.Jpeg) End Function </script> <form runat="server" form-data="form-data" multipart="multipart">
Browse for Image:
<input id="fileUpload1" type="file" size="30" runat="server" />
Jan 19, 2005 03:40 PM|vljw8202|LINK
Jan 19, 2005 05:10 PM|vljw8202|LINK
Mar 05, 2005 08:53 AM|gavinharriss|LINK
Jul 19, 2005 05:08 AM|Afgdef|LINK
Jul 22, 2005 11:38 AM|deulu|LINK
Jul 22, 2005 02:20 PM|jethompson|LINK
Jul 22, 2005 02:52 PM|tmorton|LINK
Also, you'll probably want to use a stored procedure instead of an SQL string in your code.
Jul 22, 2005 02:59 PM|jethompson|LINK
Jul 24, 2005 01:36 PM|deulu|LINK
Thanks alot for the help! It worked perfectly well....
but something about saving the image in the database... i did the following:
As String = "server=HELPDESK-04;uid=sa;pwd=**secret**;database=NaharDB"
As String = "INSERT INTO images (image_title) VALUES (@Filename)"
As SqlConnection =
As SqlCommand = New SqlCommand(commandText, MyConn)
Cmd.Parameters.Add(New SqlParameter("@Filename", SqlDbType.VarChar, 50)).Value =strfilename
What's wrong in this code, cus it keeps displaying in my database <binary> instead of the name of the image..i made sure that the type of the image_title is image.
What should be instead of ImageFilename, shouldn't it be strfilename?
i'm really sorry guys for the disturbance, but it's really important for me to figure it out...
I really appreciate your help...
Edited by moderator tmorton - do not show login credentials in your connection string!
Jul 24, 2005 02:18 PM|deulu|LINK
Jul 25, 2005 03:53 AM|deulu|LINK
Sep 12, 2005 06:03 AM|jsmythe|LINK
Sep 13, 2005 03:59 AM|Skiff|LINK
Sep 15, 2005 12:13 PM|oceanfeeling|LINK
First, you have to grab the path to the original file, your users upload.
Let's say that "image0.jpg" is the uploaded file and "image1.jpg" and "image1_thumb.jpg" are the files you create with your code.
Dim path As String = Server.MapPath("/directoryname/images/" & uploadedfile)
Dim objFile As File
Catch ex As Exception
uploadedfile is a variable for holding the original name of the picture your users upload to the server
Nov 07, 2005 06:38 AM|zioturo|LINK
This image upload free web control supports multiple image definitions (width/height and format) so you can handle up side down picture uploads.