Partial Class _Default Inherits System.Web.UI.Page
Function generateUniqueFN() Dim dateStr As String Dim randomNum As Integer Randomize() randomNum = (1000000 * Rnd)
dateStr = Year(Now()) & Month(Now()) & Day(Now()) & Hour(Now()) & Minute(Now()) & Second(Now()) & randomNum generateUniqueFN = dateStr End Function
Private Function ThumbCallback() As Boolean Return False End Function
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'get the form file collection
Dim myfiles As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
Dim strGalleryTitle As String = System.Web.HttpContext.Current.Request.Form("galleryTitle")
Dim iFile As Integer
Dim uniqueKey As String uniqueKey = generateUniqueFN() Dim conn As MySqlConnection = New MySqlConnection("server=localhost; user id=root; password=adced2258f; database=imagecrack; pooling=false;") conn.Open() For iFile = 0 To myfiles.Count - 1 ' get the posted file Dim postedFile As System.Web.HttpPostedFile = myfiles(iFile)
'make sure it is not blank If Not postedFile.FileName.Equals("") Then
Dim strRandom As String = generateUniqueFN()
'Save File to the proper directory postedFile.SaveAs(Request.MapPath("files/") & strRandom & "_" + System.IO.Path.GetFileName(postedFile.FileName))
'-------------------------------
Dim FileToResize As String = Request.MapPath("files/") & strRandom & "_" + System.IO.Path.GetFileName(postedFile.FileName)
Dim originalBitmap As Bitmap = Bitmap.FromFile(FileToResize, True) Dim newbmp As Bitmap = New Bitmap(160, 160)
Dim WidthVsHeightRatio As Double = CType(originalBitmap.Width, Single) / CType(originalBitmap.Height, Single)
Dim newg As Graphics = Graphics.FromImage(newbmp)
newg.Clear(Color.White) If WidthVsHeightRatio = 1D Then newg.DrawImage(originalBitmap, 0, 0, 100, 100) newg.Save() ElseIf WidthVsHeightRatio < 1D Then 'Image is taller than wider newg.DrawImage(originalBitmap, New RectangleF(New PointF(CType(100 - 365 * WidthVsHeightRatio / 2, Single), -50), New SizeF(CType(300 * WidthVsHeightRatio, Single), 300.0F))) newg.Save() Else 'Image is wider than taller Dim inverse As Double = Math.Pow(WidthVsHeightRatio, -1) newg.DrawImage(originalBitmap, New RectangleF(New PointF(-50, CType(100 - 350 * inverse / 2, Single)), New SizeF(300.0F, CType(300 * inverse, Single)))) newg.Save() 'newg.SmoothingMode = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected 'newg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias ' newg.SmoothingMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor newg.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality End If
'------------------------------- Dim myFileName As String = strRandom & "_" + System.IO.Path.GetFileName(postedFile.FileName) Dim userIP As String = Request.UserHostAddress
Dim cmd As MySqlCommand = New MySqlCommand("INSERT INTO images (image_filename,unique_key,user_ip) VALUES ('" & myFileName & "','" & uniqueKey & "','" & userIP & "') ", conn) cmd.ExecuteNonQuery()
' Label1.Text = strRandom & "_" + System.IO.Path.GetFileName(postedFile.FileName) & " has been uploaded" End If
Next iFile 'conn.Close() ' conn.Dispose() fileLabel.Text = "File(s):"
' Dim conn As MySqlConnection = New MySqlConnection("server=localhost; user id=root; password=adced2258f; database=imagecrack; pooling=false;") ' conn.Open() Using cmd As MySqlCommand = New MySqlCommand("SELECT * FROM images WHERE unique_key = '" & uniqueKey & "' ", conn)
Dim reader As MySqlDataReader = cmd.ExecuteReader
' Call Read before accessing data. bbCodeLabel.Text &= "<textarea rows=15 cols=80>" While reader.Read()
bbCodeLabel.Text &= "[URL=http://localhost:3186/imagecrack/image.aspx?f=" & reader("image_filename") & "][IMG]http://localhost:3186/upload2/files/tn_" & reader("image_filename") & "[/IMG][/URL]" & vbCrLf End While bbCodeLabel.Text &= "</textarea>"
' Call Close when done reading. reader.Close() End Using
Kan du kort give mig en lekture i hvad me, my_file_element og ClientID gør?
Jeg formoder at me henviser til aspx-sidens content place holder, men hvad nu hvis man havde flere placeholdere..
Tak..
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.