我正在创建一个内容管理系统(CMS),我被要求包括图片上传,图片的要求如下:
Check that the image in JPEG or PNG format.
Check to see that an image with the same filename isn’t already stored on your site.
Check that the image file is under 150K in size and the image is no greater than 400 X 400 pixels (if not the image must be resized to that specification).
The image must be stored in a folder and not in the database itself
The image must referenced in a relevant database table
到目前为止,我有以下代码:
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Dim filename As String
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath("~/Images/Property/") + filename)
Dim width As Integer = img.Size.Width
Dim height As Integer = img.Size.Height
If PhotoUploadControl.PostedFile.ContentLength < 153600 Then
If PhotoUploadControl.HasFile Then
If PhotoUploadControl.PostedFile.ContentType = "image/jpeg" Then
If PhotoUploadControl.PostedFile.ContentLength < 153600 Then
Try
filename = Path.GetFileName(PhotoUploadControl.FileName)
PhotoUploadControl.SaveAs(Server.MapPath("~/Images/Property/") + filename)
StatusLabel.Text = "Upload status: File uploaded!"
Catch ex As Exception
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message
End Try
Else
StatusLabel.Text = "Please upload an image"
End If
Else
StatusLabel.Text = "Please upload an image less than 150k"
End If
End If
End If
End Sub
有谁知道我会怎么做?