关于CreateObject("Adodb.Stream")的问题

yzg614 2005-04-14 07:39:52
我想上传文件的时候在数据库中只保存相对路径,如../upfile. 而不是http://127.0.0.1/upfile. 请问有没有好的方法?

if file.FileSize>0 then
file.SaveAs Server.mappath(FileName) ////取路径
if methods = 1 then
response.write "<script>parent.WBTB_Composition.document.body.innerHTML+='<br><a href="& filename &"><img border=0 src=images/"&fileEXT&".gif>点击下载浏览该文件"& filename &"</a>'</script>"
else
response.write "<script>parent.WBTB_Composition.document.body.innerHTML+='<br><img border=0 src="&filename&">'</script>"
end if
end if


function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
...全文
502 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzg614 2005-04-18
  • 打赏
  • 举报
回复
一样吧
  • 打赏
  • 举报
回复
数据库是数据库,你保存在数据库里的路径和实际路径是两回事,实际你还要写上server.mappath才可以的
yzg614 2005-04-15
  • 打赏
  • 举报
回复
直接存会在 dr.SaveToFile FullPath,2 这一行出错.SaveToFile要求得是全路径
underone 2005-04-15
  • 打赏
  • 举报
回复
直接存../upfile/"&filename&"
yzg614 2005-04-15
  • 打赏
  • 举报
回复
?
qunluo 2005-04-15
  • 打赏
  • 举报
回复
<%OPTION EXPLICIT%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传中,请稍候....</title>
<link rel="stylesheet" href="css.css" type="text/css">
</head>
<body>
<br>文件正在上传中,请稍候....<hr size=1 noshadow width=300 align=left><br><br>
<%
dim upload,file,formName,formPath,iCount,url
set upload=new upload_5xSoft ''建立上传对象

response.write upload.Version&"<br><br>" ''显示上传类的版本

if upload.form("filepath")="" then ''得到上传目录
HtmEnd "请输入要上传至的目录!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if

iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(formPath&file.FileName) ''保存文件
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" succeed!<br>"

iCount=iCount+1
end if
set file=nothing
next
set upload=nothing ''删除此对象
Htmend iCount&" 文件上传成功 !"

sub HtmEnd(Msg)
set upload=nothing
response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">Back</a>]</body></html>"
response.end
end sub
%>
</body>
</html>

就是你象要的
yzg614 2005-04-14
  • 打赏
  • 举报
回复
你的意思是在从数据库读出来显示文件的的时候把路径替换掉吧,. 我想直接在写入数据库的时候就是../upfile 的格式
wzgme 2005-04-14
  • 打赏
  • 举报
回复
如果是固定的,replace替换掉啊。
yzg614 2005-04-14
  • 打赏
  • 举报
回复
请问怎么实现?
iuhxq 2005-04-14
  • 打赏
  • 举报
回复
当然可以

28,405

社区成员

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

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