请教高手!关于无组件上传图片时的问题

developerworks 2003-08-12 11:37:21
http://www.csdn.net/develop/Read_Article.asp?Id=20378
此贴子中,我利用无组件上传图片至数据库。
现在存在一个问题非常头痛就是,如果上传图片是可选的,也就是说我可以上传图片也可以不上传图片,在下列代码中如何解决?
***********************************************************
/* transact1.asp*/
<!--#include file="../func/conn.inc"-->
<!--#include file="../func/fupload.inc"-->
<!--#include file ="../func/myfunctions.inc"-->
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
Dim Fields
Dim strTitle,strSort,strContent
Dim rs,sSql
Dim iMaxid
Dim strMaxid
Dim strlen

Set Fields = GetUpload()
strTitle=BinaryToString(Fields("txtTitle").value)
strSort=BinaryToString(Fields("txtSort").value)
strContent=BinaryToString(Fields("txtContent").value)
strSort=split(trim(strSort),"-")

if instr(1,lcase(Fields("file").FileName),".jpg")=0 and instr(1,lcase(Fields("file").FileName),".gif")=0 then
response.write "<script language='javascript'>alert('上传的图片必须是gif或者jpg格式的图片')</script>"
response.write "<script language='javascript'>window.location='addemployee.asp';</script>"
Response.end
end if

if Fields("file").Length>500000 then
response.write "<script language='javascript'>alert('只允许不大于500k的图片上传');</script>"
response.write "<script language='javascript'>window.location='addemployee.asp';</script>"
response.end
end if

'/*存至数据库*/
if Fields("file").FileName<>"" then
Set rs=Server.CreateObject("ADODB.Recordset")
sSql="select * from employee order by id desc"
rs.open sSql,conn,2,2
if not rs.eof then
iMaxid=Clng(rs("id"))+1
strlen=4-len(cstr(iMaxid))
strMaxid=string(strlen,"0") & cstr(iMaxid)
else
strMaxid="0001"
end if
rs.addnew
rs("id")=strMaxid
rs("title")=strTitle
rs("sort")=strSort(0)
rs("img").AppendChunk Fields("file").Value
rs("content")=quoteChg(strContent)
rs("todate")=date()
rs.update
rs.close
response.write "<script language='javascript'>alert('添加记录成功')</script>"
end if
end if
%>

...全文
18 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
developerworks 2003-08-12
  • 打赏
  • 举报
回复
不行,我试过了,不知哪位高手能帮忙!
ferrari 2003-08-12
  • 打赏
  • 举报
回复
你if then else不就行了吗?

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧