我的文件
名称:Response.AddHeader "content-disposition", "attachment; filename="&rs("user")
类型:response.ContentType="image/jpeg"
<!--#include file=conn.asp-->
<%
dim sql
dim rs
dim id
id = request("id")
on error resume next
call conn_init()
set rs=server.CreateObject("adodb.recordset")
sql="SELECT * FROM imgdata WHERE user = '" & id & "'"
rs.Open sql,conn,1,1
if rs.recordcount = 0 then
rs.close
rs.open "SELECT * FROM imgdata WHERE user = 'not_available'",conn,1,1
end if
response.ContentType="image/jpeg"
Response.BinaryWrite rs("imagedata")
Response.AddHeader "content-disposition", "attachment; filename="&rs("user")
rs.Close
endconnection
function ImageUp(formsize,formdata) '这个函数的功能是截取其中的图像部分。
bncrlf=chrb(13) & chrb(10) '做成函数后。以后你可以自己随意使用了。
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf&bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
imageup=midb(formdata,datastart,dataend)
end function
%>
-----------------
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename="&name
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
--------------------
以下是ASP图文混合上传的实例:
数据库驱动自己改一下
<% @ language=vbscript %>
upload.asp:
<html>
<head>
<meta name="VI60_defaultClientScript" content="VBScript">
<title> File Upload </title>
<script ID="clientEventHandlersVBS" LANGUAGE="vbscript">
'<!--
Sub form2_onsubmit
form1.submit
End Sub
'-->
</script>
</head>
<body>
<form name="form1" ENCTYPE="multipart/form-data" ACTION="upimage.asp" METHOD="POST" target="_blank">
Please choose a picture to upload: <br>
<input NAME="picture" TYPE="FILE"> <br>
</form>
<form name="form2" action="uptext.asp" method="post">
<input type="text" name="text1"><br>
<input type="text" name="text2"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
upimage.asp
<%
FormSize = Request.TotalBytes
FormData = Request.BinaryRead( FormSize )
function ImageUp(formsize,formdata)
bncrlf=chrb(13) & chrb(10)
divider=leftb(formdata,instrb(formdata,bncrlf)-1)
datastart=instrb(formdata,bncrlf&bncrlf)+4
dataend=instrb(datastart+1,formdata,divider)-datastart
imageup=midb(formdata,datastart,dataend)
end function
Image=ImageUp (FormSize,Formdata)
set rs=server.CreateObject("adodb.recordset")
strconn="driver={microsoft access driver (*.mdb)};dbq="&server.MapPath("test.mdb")
sql="SELECT * FROM imgtable"
rs.Open sql,strconn,1,3
rs.AddNew
rs("img").appendchunk Image
rs.Update
rs.Close
response.contenttype="image/gif"
response.binarywrite imageup(formsize,formdata)
%>
uptext.asp
<% @ language=vbscript %>
<%
strconn="driver={microsoft access driver (*.mdb)};dbq="&server.MapPath("test.mdb")
text1=request.form("text1")
text2=request.form("text2")
response.write text1
response.write text2
set rs=Server.CreateObject("adodb.recordset")
sql="SELECT top 1 * FROM imgtable ORDER BY id DESC"
rs.Open sql,strconn,1,3
rs("text1")=text1
rs("text2")=text2
rs.Update
rs.Close
%>
show.asp
<%@ Language=VBScript %>
<%
strconn="driver={microsoft access driver (*.mdb)};dbq="&server.MapPath("test.mdb")
set rs=Server.CreateObject("adodb.recordset")
sql="SELECT top 1 * FROM imgtable ORDER BY id DESC"
rs.Open sql,strconn,1,3
%>
<html>
<body>
以下是你的上传资料。<br>
文本一:<% Response.Write rs("text1") %><br>
文本二:<% Response.Write rs("text2") %><br>
你的图像:
<img src=showimg.asp?id=<%=rs("id")%>>
</body>
</html>
showimg.asp
<%@ Language=VBScript %>
<%
strconn="driver={microsoft access driver (*.mdb)};dbq="&server.MapPath("test.mdb")
id=Request("id")
set rs=server.CreateObject("adodb.recordset")
sql="SELECT * FROM imgtable where id="&id
rs.Open sql,strconn,1,3
response.contenttype="image/gif"
Response.BinaryWrite rs("img")
%>