Private Sub btaddpic1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btaddpic1.Click
If Request.IsAuthen
ticated then
If Request.QueryString.HasKeys then
If upimg3.Value.ToString <> ""
And upimg3.PostedFile.ContentLength > 0 then
'判断图片不能大于130k
If upimg3.PostedFile.ContentLength <= 132000 then
''-------改的是这里----------
Dim file_name, file_time As String
file_name = upimg3.PostedFile.FileName.ToString()
file_time = DateTime.Now.Year.ToString + DateTime.Now.Month.ToString + DateTime.Now.Day.ToString + DateTime.Now.Hour.ToString + DateTime.Now.Minute.ToString + DateTime.Now.Second.ToString + DateTime.Now.Millisecond.ToString()
'显示上一次上传的文件名
Dim lastfilename As String = file_name
'构建出上传的以时间表示的文件名
'判断文件后缀分大小写
If file_name.Substring(file_name.IndexOf("."
+ 1) = "jpg"
Or file_name.Substring(file_name.IndexOf("."
+ 1) = "gif"
Or file_name.Substring(file_name.IndexOf("."
+ 1) = "JPEG"
Or file_name.Substring(file_name.IndexOf("."
+ 1) = "JPG"
Or file_name.Substring(file_name.IndexOf("."
+ 1) = "GIF"
Or file_name.Substring(file_name.IndexOf("."
+ 1) = "jpeg"
then
file_name = "/"
+ file_time + CStr(getrandomint()) + file_name.Substring(file_name.IndexOf("."
, file_name.Length - file_name.IndexOf("."
)
'不能有同名的图片
If File.Exists(Server.MapPath(Request.ApplicationPath) + "/community/community_images"
+ file_name) = False then
Try
'存储图片路径(Server.MapPath(Request.ApplicationPath) + "/upimages"
+ file_name)
upimg3.PostedFile().SaveAs(Server.MapPath(Request.ApplicationPath) + "/community/community_images"
+ file_name)
'相对路径写进数据库
Dim strurl As String
strurl = "community_images"
+ file_name
If Not insert_img_url(strurl) then
lblmsg2.Visible() = True
lblmsg2.BackColor() = Color.FromName("#FFF3EF"
lblmsg2.BorderColor() = Color.FromName("#FF6500"
lblmsg2.Text() = "<font color=red>·</font>图片写入数据库失败,请稍后再试!"
Exit Sub
End If
Catch ex As Exception
lblmsg2.Visible() = True
lblmsg2.BackColor() = Color.FromName("#FFF3EF"
lblmsg2.BorderColor() = Color.FromName("#FF6500"
lblmsg2.Text() = "<font color=red>·</font>图片写入失败,请稍后再试!"
Finally
Response.Redirect("success_uppic.aspx?lastpic="
+ Server.UrlEncode(lastfilename) + "&id="
+ Request.QueryString("id"
.ToString + "&sort="
+ Request.QueryString("sort"
.ToString + "&cid="
+ Request.QueryString("cid"
.ToString + "&flg="
+ Request.QueryString("flg"
.ToString + "&page="
+ Request.QueryString("page"
.ToString)
End Try
End If
End If
else
lblmsg2.Visible() = True
lblmsg2.BackColor() = Color.FromName("#FFF3EF"
lblmsg2.BorderColor() = Color.FromName("#FF6500"
''-------改的是这里----------
lblmsg2.Text = "<font color=red>·</font>请上传图片大小在130k以内."
End If
End If
End If
End If
End Sub