» 首页 » 电脑_数码 » 编程 » 关于上传图片,将途经存入access数据库的问题

关于上传图片,将途经存入access数据库的问题

上传图片,将相对路径存入数据库,我的思路是这样的:
1、点击“上传”按钮,打开“upfile.htm”网页。
onClick="javascript:window.open('upfile.htm','','width=580,height=160,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=no')

2、file.htm主要代码如下:

<form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" onsubmit="checkImage('file1')">

<input type="hidden" name="filepath" value="../bookpic/"> 文件: <input type="file" name="file1" style="width:400" class="tx1" value="">

3、upfile.asp代码:
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆!');history.go(-1);</script>"
response.End
end if
%>
<%OPTION EXPLICIT%>
<!--#include FILE="upload_ckxp.inc"-->
<html>
<head>
<title>图片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body bgcolor="#E8F1FF">
<%
dim upload,file,formName,formPath,iCount
'response.write request.form("testtext")
set upload=new upload_5xSoft ''建立上传对象

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

if upload.form("filepath")="" then ''得到上传目录
HtmEnd "请输入要上传至的目录!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")&year(now)&month(now)&"/"
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"&year(now)&month(now)&"/"
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&"成功!<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();"">返回</a>]"
response.End
end sub
%>
</body>
</html>


我弄了好长时间,可还是不知道哪里错了,请各位高手帮帮忙!谢谢啦!

注:我想存的相对路径是 ../bookpic/2003**/**.jpg,数据库的属性是bookpic


[a,b]=y(2)
a = 4
b = 5

else
formPath=upload.form("filepath")&year(now)&month(now)&"/"
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"&year(now)&month(now)&"/"
end if

加上


file.SaveAs Server.mappath(formPath&file.FileName) ''保存文件


这个地方出错了..


upload_5xSoft 不能创建目录.只能将文件保存到已经存在的目录下.

如要建立目录.请用fso



创建文件夹
dim fso
set fso = server.CreateObject("Scripting.FileSystemObject")
fso.CreateFolder("C:\test") '目标文件夹的父文件夹必须存在
set fso = nothing

判断文件夹是否存在
dim fso
set fso = server.CreateObject("Scripting.FileSystemObject")
if fso.FolderExists("C:\Windows") then
response.Write("目标文件夹存在")
else
response.Write("目标文件夹不存在")
end if
set fso = nothing

删除文件夹
dim fso
set fso = server.CreateObject("Scripting.FileSystemObject")
fso.DeleteFolder("C:\test") '文件夹不必为空
set fso = nothing



刚写了一个不管父目录存在与否都创建目录的代码:

Sub createFolder(p)
'On Error Resume Next
if right(p,1)="\" then p=left(p,len(p)-1)
dim pp:pp=Left(p, instrrev(p,"\"))
If not Server.CreateObject("Scripting.FileSystemObject").FolderExists(pp) Then createFolder(pp)
Server.CreateObject("Scripting.FileSystemObject").CreateFolder(p)
End Sub

createFolder("c:\xx\xx\xx\xx\x\x\x\x\")


唉.帮你把upfile.asp改写了下




<%OPTION EXPLICIT%>
<%if session("admin")="" then
response.Write "<script language='javascript'>alert('网络超时或您还没有登陆!');history.go(-1);</script>"
response.End
end if
%>
<!--#include FILE="upload_ckxp.inc"-->
<html>
<head>
<title>图片上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<body bgcolor="#E8F1FF">
<%
dim upload,file,formName,formPath,iCount
'response.write request.form("testtext")
set upload=new upload_5xSoft ''建立上传对象

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

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

iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
'建立目录
createFolder(Server.mappath(formPath))

file.SaveAs Server.mappath(formPath&file.FileName) ''保存文件
response.Write file.FilePath&file.FileName&"("&file.FileSize&")=>"&formPath&File.FileName&"成功!<br>"
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing ''删除此对象
HtmEnd iCount&"个文件上传结束!"

'建目录过程
Sub createFolder(p)
On Error Resume Next
if right(p,1)="\" then p=left(p,len(p)-1)
dim pp:pp=Left(p, instrrev(p,"\"))
If not Server.CreateObject("Scripting.FileSystemObject").FolderExists(pp) Then createFolder(pp)
Server.CreateObject("Scripting.FileSystemObject").CreateFolder(p)
End Sub

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




要是回答的内容有问题,或认为不妥,请发送百度消息给我,消息内容加上本页网址哦。。

·

 相关问题
·关于上传图片,将途经存入access数据库的问题
·matlab中多个输出参数如何显示???
·flash迷宫游戏
·帮忙写段代码,显示百度主页
·函数重载的问题
·怎样在EXCEL2007里面做函数输出不同的答案,字体颜色不一样
·求一道VF编程...我们的作业
·什么是开放性城市,它是怎么定义?
·3d 在web中用什么技术可以实现
·有没有什么代码可以让网页横着动的?
·执行下面的程序段后,*(ptr+5)的值为??
·数学建模 对计算机有那些要求,特别是C++方面的。
·php5 session保存对象
·mysql+php的时候,有时候为什么php会找不到mysql
·用DM清0后数据恢复100分!

 《关于上传图片,将途经存入access数据库的问题》答案收集时间:2008-06-14 14:37:23



©2007 电脑技术问答录