ASP调用数据库图片问题(Access)。

走在风中 2010-05-05 12:32:38
RT!
图片都放在一个文件夹里的,想把图片放到数据库,然后用ASP调用图片的绝对路径,显示图片。
请问如何将图片存入到数据库中,还有如何用ASP调用图片?
还请高手指点!
...全文
249 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sy_binbin 2010-05-05
  • 打赏
  • 举报
回复
把图片的路径保存在数据库里多好啊!
toury 2010-05-05
  • 打赏
  • 举报
回复
1、遍历D:\image\文件夹;
2、检查每个遍历到的文件是否是图片格式
3、创建一个数据库表,或在某个现有表里加个字段,例如img_URL
4、将图片格式文件写入数据库
conn.execute("UPDATE 表(img_URL) VALUES('"&遍历得到的文件(包括目录)名&"')")
5、使用:
<%
rs.open ....,conn,1,1
i=0
n=4'一行n张图片
do while not rs.eof
imgSrc=rs("img_URL")
response.write"<img src='"&imgSrc&"'>"
if i mod n=0 then response.write "<br>"
rs.movenext
i=i+1
loop
rs.close
%>
走在风中 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sy_binbin 的回复:]
引用 4 楼 krayli 的回复:
引用 2 楼 wanyoulin 的回复:
1. 无组件上传,并将图片名称保存到数据库。代码如下:
<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0……
[/Quote]

大哥,给个例子噻。
比如,我的图片放在D:\image文件夹里,如果保存路径的话,那怎么弄呢 ?
还请大哥指教一二。
sy_binbin 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 krayli 的回复:]
引用 2 楼 wanyoulin 的回复:
1. 无组件上传,并将图片名称保存到数据库。代码如下:
<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "……
[/Quote]


不管你要啥效果,把路径保存到数据库中才是真正解决问题的方法
走在风中 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wanyoulin 的回复:]
1. 无组件上传,并将图片名称保存到数据库。代码如下:
<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xh……
[/Quote]
我是不需要上传图片的,图片是现成的。
我需要的效果是那种幻灯片的效果,图片自动切换。
走在风中 2010-05-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sy_binbin 的回复:]
把图片的路径保存在数据库里多好啊!
[/Quote]
因为自己在数据库这个方面还有点小白,所以还不知道如何实现,请高手指点一下。如何实现捏?
wanyoulin 2010-05-05
  • 打赏
  • 举报
回复
1. 无组件上传,并将图片名称保存到数据库。代码如下:
<%
Response.Buffer = True
Server.ScriptTimeOut=9999999
On Error Resume Next
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta content="all" name="robots" />
<meta name="author" content="木目,Woodeye" />
<meta name="description" content="木目ASP文件上传工具" />
<meta name="keywords" content="木目,ASP,Upload,文件上传" />
<style type="text/css">
<!--
body,input {font-size:12px;}
-->
</style>
<title>木目ASP文件上传工具 </title>
</head>
<body id="body">
<%
ExtName = "jpg,gif,png,txt,rar,zip,doc" '允许扩展名
SavePath = "upload" '保存路径
If Right(SavePath,1) <>"/" Then SavePath=SavePath&"/" '在目录后加(/)
CheckAndCreateFolder(SavePath)

UpLoadAll_a = Request.TotalBytes '取得客户端全部内容
If(UpLoadAll_a>0) Then
Set UploadStream_c = Server.CreateObject("ADODB.Stream")
UploadStream_c.Type = 1
UploadStream_c.Open
UploadStream_c.Write Request.BinaryRead(UpLoadAll_a)
UploadStream_c.Position = 0

FormDataAll_d = UploadStream_c.Read
CrLf_e = chrB(13)&chrB(10)
FormStart_f = InStrB(FormDataAll_d,CrLf_e)
FormEnd_g = InStrB(FormStart_f+1,FormDataAll_d,CrLf_e)

Set FormStream_h = Server.Createobject("ADODB.Stream")
FormStream_h.Type = 1
FormStream_h.Open
UploadStream_c.Position = FormStart_f + 1
UploadStream_c.CopyTo FormStream_h,FormEnd_g-FormStart_f-3
FormStream_h.Position = 0
FormStream_h.Type = 2
FormStream_h.CharSet = "GB2312"
FormStreamText_i = FormStream_h.Readtext
FormStream_h.Close

FileName_j = Mid(FormStreamText_i,InstrRev(FormStreamText_i,"\")+1,FormEnd_g)
If(CheckFileExt(FileName_j,ExtName)) Then
SaveFile = Server.MapPath(SavePath & FileName_j)

If Err Then
Response.Write "文件上传: <span style=""color:red;"">文件上传出错! </span>  <a href=""" & Request.ServerVariables("URL") &""">重新上传文件 </a> <br />"
Err.Clear
Else
SaveFile = CheckFileExists(SaveFile)

k=Instrb(FormDataAll_d,CrLf_e&CrLf_e)+4
l=Instrb(k+1,FormDataAll_d,leftB(FormDataAll_d,FormStart_f-1))-k-2
FormStream_h.Type=1
FormStream_h.Open
UploadStream_c.Position=k-1
UploadStream_c.CopyTo FormStream_h,l
FormStream_h.SaveToFile SaveFile,2

SaveFileName = Mid(SaveFile,InstrRev(SaveFile,"\")+1)

DbPath = Server.MapPath("Data/Magic.mdb")
Set conn = CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbPath & ";"
set rs = CreateObject("adodb.recordset")
rs.CursorLocation = 3
rs.open "select * from pic where 1=0",conn,1,3
rs.addnew
rs("picname")=savefilename
rs("username")=request.cookies("Cnhww")("username")
rs("Addtime")=now()
rs("addname")=savefilename
rs("location")=savefile
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
Response.write "文件上传: <span style=""color:red;"">" & SaveFileName & " </span>文件上传成功!  <a href=""" & Request.ServerVariables("URL") &""">继续上传文件 </a> <br />"
End If
Else
Response.write "文件上传: <span style=""color:red;"">文件格式不正确! </span>  <a href=""" & Request.ServerVariables("URL") &""">重新上传文件 </a> <br />"
End If

Else
%>
<script language="Javascript">
<!--
function ValidInput()
{

if(document.upform.upfile.value=="")
{
alert("请选择上传文件!")
document.upform.upfile.focus()
return false
}
return true
}
// -->
</script>
<form action=' <%= Request.ServerVariables("URL") %>' method='post' name="upform" onsubmit="return ValidInput()" enctype="multipart/form-data"">
文件上传:
<input type='file' name='upfile' size="40"> <input type='submit' value="上传">
</form>
<%
End if
Set FormStream_h = Nothing
UploadStream.Close
Set UploadStream = Nothing
%>
</body>
</html>
<%
'判断文件类型是否合格
Function CheckFileExt(FileName,ExtName) '文件名,允许上传文件类型
FileType = ExtName
FileType = Split(FileType,",")
For i = 0 To Ubound(FileType)
If LCase(Right(FileName,3)) = LCase(FileType(i)) then
CheckFileExt = True
Exit Function
Else
CheckFileExt = False
End if
Next
End Function

'检查上传文件夹是否存在,不存在则创建文件夹
Function CheckAndCreateFolder(FolderName)
fldr = Server.Mappath(FolderName)
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fldr) Then
fso.CreateFolder(fldr)
End If
Set fso = Nothing
End Function

'检查文件是否存在,重命名存在文件
Function CheckFileExists(FileName)
Set fso=Server.CreateObject("Scripting.FileSystemObject")
If fso.FileExists(SaveFile) Then
i=1
msg=True
Do While msg
CheckFileExists = Replace(SaveFile,Right(SaveFile,4),"_" & i & Right(SaveFile,4))
If not fso.FileExists(CheckFileExists) Then
msg=False
End If
i=i+1
Loop
Else
CheckFileExists = FileName
End If
Set fso=Nothing
End Function
%>

2. ASP调用图片:先建查询 “q” 然后在图片要显示的位置插入代码:
<%=LTRIM(RTRIM(q.Fields.Item("pic").Value))%>

无组件上传参考:http://topic.csdn.net/u/20091006/13/dfd2fe36-0676-46ef-b076-bc48cb78add4.html

28,390

社区成员

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

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