나는 콘텐츠 관리 시스템 (CMS)을 만드는 오전 내에는 FileUpload 도구를 사용하여 이미지를 업로드 및 I 이미지 업로드를 포함하도록 요청을받은, 이미지의 요구 사항은 다음과 같습니다 :비주얼 스튜디오
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
나는이 문제에 대해 어떻게 생각합니까?
거의 다 왔으니 문제가 뭐니? – Kenneth
내가 여기에서 멈췄다 - 이미지 파일의 크기가 150K 미만이고 이미지의 크기가 400x400 픽셀보다 크지 않은지 확인하십시오 (이미지가 해당 사양으로 리사이즈되어야하는 경우). 또한 <102400에서 150k까지 어떻게 변경합니까? –