关于文件上传的问题...在线急等兄弟们伸出援助之手...
以下是tougao.asp的代码..<!--#include file="inc/conn.asp" -->
<!--#include FILE="upload.inc"-->
<%
if request("save")="yes" then '当点击发表文章的时候..
on Error resume next
response.buffer=true
set upload=new upload_5xSoft
set image=upload.File("img")
imgname=image.filename
if image.filename<>"" then
imgname=getfilename(image.filename)
image.SaveAs Server.MapPath("images/"&imgname)
end if
dim errstr
dim authorname
dim bookname
dim articlename
dim booksort
dim content
dim vipuser
dim bookjianjie
errstr=""
authorname=trim(request("authorname"))
bookname=trim(request("bookname"))
articlename=trim(request("articlename"))
bookjianjie=trim(request("bookjianjie"))
booksort=trim(request("booksort"))
vipuser=trim(request("vipuser"))
content=trim(request("content"))
if session("loginok")=false then
errstr=errstr&"<br>·你还未登录.请返回首页<a href='index.asp'>登录</a><br>"
end if
if trim(request("authorname"))="" then
errstr=errstr&"<br>·作者名不能为空.<br>"
end if
if trim(request("bookname"))="" then
errstr=errstr&"<br>·书名不能为空.可以与文章名相同<br>"
end if
if request("articlename")="" then
errstr=errstr&"<br>·文章名不能为空.<br>"
end if
if request("content")="" then
errstr=errstr&"<br>·文章内容不能为空.<br>"
end if
if len(request("authorname"))<4 then
errstr=errstr&"<br>·作者名应该在2个汉字或4个字符以上."
end if
If Instr(request("authorname"),"=")>0 or Instr(request("authorname"),"%")>0 or Instr(request("authorname"),chr(32))>0 or Instr(request("authorname"),"?")>0 or Instr(request("authorname"),"&")>0 or Instr(request("authorname"),";")>0 or Instr(request("authorname"),",")>0 or Instr(request("authorname"),"'")>0 or Instr(request("authorname"),"?")>0 or Instr(request("authorname"),chr(34))>0 or Instr(request("authorname"),chr(9))>0 or Instr(request("authorname"),"?")>0 or Instr(request("authorname"),"$")>0 or Instr(request("authorname"),">")>0 or Instr(request("authorname"),"<")>0 or Instr(request("authorname"),"@")>0 or Instr(request("authorname"),"""")>0 then
errstr=errstr&"<br>·作者名含有非法字符.<br>"
end if
if session("loginok")=true and errstr="" then
SQL="insert into book(bauthor,bname,articlename,bphoto,vipuser,bsort,articlecontent,bjianjie) Values('"&authorname&"','"&bookname&"','"&articlename&"','"&imgname&"','"&vipuser&"','"&booksort&"','"&content&"','"&bookjianjie&"')"
cnobj.Execute SQL
function getfilename(imgname)
getfilename=replace(replace(replace(cstr(now)," ",""),"-",""),":","")&radm()&right(imgname,4)
end function
response.write "<script language=javascript>alert('发表成功.!');"
response.write "javascript:history.go(-1)</script>"
end if
end if
%>
<script language="javascript">
function radm()
{
return Math.round(Math.random()*100)
}
</script>
<body>
...
</body>
---问题:
以上代码能够实现数据操作.但是图片文件无法上传到服务器的images文件夹下.并且数据库无法得到imgname的值.
如果去掉on error resume next的话会提示upload.file(..)不支持什么的..
请朋友们帮忙下下..谢谢了..在线急等..
代码功能需求:>实现图片上传到服务器.并且新数据能插入到数据库...
[[it] 本帖最后由 sunfishy 于 2008-7-30 10:14 编辑 [/it]]