Dim AFilePhoto As String = ""
AFilePhoto = Trim(Me.FilePhoto.PostedFile.FileName)
If FilePhoto.PostedFile.FileName <> "" Then
'判断上传的照片是否存在
If Me.FilePhoto.PostedFile.ContentLength > 0 Then
'判断上传文件的大小
If Me.FilePhoto.PostedFile.ContentLength > 1024 * 1024 * 1 Then
Me.Response.Write("<script language=""vbs"">alert""上傳的照片不能大於1MB!""</script>")
Page.RegisterStartupScript("focus", "<script language=javascript>document.all('FilePhoto').focus()</script>")
Exit Sub
End If
'获取图象名称
AFilePhoto = AFilePhoto.Substring(AFilePhoto.LastIndexOf("\"))
'比较上传文件名与预设文件名格式是否相同
If AFilePhoto.Substring(1, AFilePhoto.LastIndexOf(".") - 1) <> "YGZP" & Trim(Me.txtUserID.Text) Then
Dim errMsg As String
errMsg = "員工照片名無效!請輸入:YGZP" & Trim(Me.txtUserID.Text) & ".擴展名"
'Me.Response.Write("<script language=""vbs"">alert'" & errMsg & "'</script>")
Response.Write("<script>alert('" & errMsg & "')</script>")
Page.RegisterStartupScript("focus", "<script language=javascript>document.all('FilePhoto').focus()</script>")
Exit Sub
End If
'获取服务器中图象文件夹路径
AFilePhoto = "Image\Photo" & AFilePhoto
Else
Me.Response.Write("<script language=""vbs"">alert""上傳的照片不存在或照片沒有內容!""</script>")
Page.RegisterStartupScript("focus", "<script language=javascript>document.all('FilePhoto').focus()</script>")
Exit Sub
End If
End If
‘如果附件不存在就保存
If File.Exists(Me.Server.MapPath(AFilePhoto)) = False Then
Me.FilePhoto.PostedFile.SaveAs(Me.Server.MapPath(AFilePhoto))
End If