我已经检查了文件大小和文件扩展名。但是我仍然需要检查上传过程是否超时。如果确实如此,我想向用户显示上传超时的消息,他们可以稍后再试。任何帮助将不胜感激!:)
Dim success As Boolean = False
Response.Write("*EIL*")
Try
If Not Context.Request.Files Is Nothing Then
Dim fileCount As Int32 = Context.Request.Files.Count
For fileLoop As Integer = 0 To fileCount - 1
Dim file As HttpPostedFile = Context.Request.Files(fileLoop)
Dim fileName As String
If file.ContentLength > 20971520 Then
Response.Write("The upload failed because the file size is too large - 20MB is the limit.")
Else
fileName = HttpUtility.UrlDecode(file.FileName)
Dim ext As String = fileName.Substring(fileName.Length - 4, 4).ToLower
If ext = ".jpg" Or ext = ".gif" Or ext = ".png" Or ext = ".bmp" Or ext = ".psd" Or ext = ".tif" Then
If InStr(fileName, "\") > 0 Then
Dim arr() As String = Split(fileName, "\")
fileName = arr(arr.Length - 1)
End If
file.SaveAs(String.Format(ConfigurationManager.AppSettings("ArtworkUploadPath"), fileName))
success = True
Else
Response.Write("The upload failed because the file was the wrong type. Only files with the following extensions are allowed: .jpg, .gif, .png, .bmp, .psd, .tif")
End If
End If
Next
If success Then Response.Write("Success")
End If
Catch ex As Exception
End Try