网上贴图区经常看到回复一次就变一次的贴子,觉得好玩,不明白其原理.后网上找一篇文章.讲原理是链到一个asp页,实现源码也给了:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
'----------------------------------------------------------------------------------------
'转发时请保留松餍畔?这段声明不并会影响你的显示速度!
'************************* 随机图片显示 ****************************
'使用实例:img.asp?list=图片存放目录
'使用注意:图片目录放于本文件同目录下!需要FSO支持!
'说明:只要将变化图片放于一个目录下,修改下面程序的(需要修改的地方)成你的目录名称!
' 上传本程序和图片文件夹到同一目录下,在发帖时候使用UBB代码形如:即可!
'----------------------------------------------------------------------------------------
Function AllPath()
Dim Domain,GFilePath
Domain = Request.ServerVariables("SERVER_NAME")
GFilePath = Request.ServerVariables("PATH_INFO")
GFilePath = lcase(left(GFilePath,instrRev(GFilePath,"/")))
AllPath = "http://"&Domain&GFilePath
End Function
Function ShowFileList(folderspec)
Dim Path,objFSO,objFolder,count,objFile,nume,S
Path = Server.MapPath(folderspec)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(Path) Then
Set objFolder = objFSO.GetFolder(Path)
count = 0
For Each objFile in objFolder.Files
count = count+1
Next
randomize
nume = Int((count*rnd)+1)
S = 0
ShowFileList = ""
For Each objFile in objFolder.Files
S = S + 1
If S = nume Then
ShowFileList = objFile.Name
Exit For
End If
Next
Set objFolder = Nothing
Else
ShowFileList = "NO"
End If
Set objFSO = Nothing
End Function
Dim list,2004528115924.htm,address,str
list = trim(Request.QueryString("list"))
if list = "" then
Response.write "本页需要正确参数引入,您缺少相关的参数!正确格式如下:"&AllPath&"img.asp?list=(adpic)"
Response.End()
end if
2004528115924.htm = ShowFileList("./"&list&"/")
if 2004528115924.htm = "NO" then
Response.write "您指定的目录<b>"&list&"</b>不存在,请重新指定!"
Response.End()
end if
if 2004528115924.htm = "" then
Response.write "您指定的目录<b>"&list&"</b>没有相关的图片文件存在,请重新指定!"
Response.End()
end if
str = right(2004528115924.htm,3)
if str<>"jpg" and str<>"gif" then
2004528115924.htm = "erro.gif"
end if
address = AllPath&list&"/"
address = address&2004528115924.htm
%>
<%Response.redirect(address)%>以上的程序可能有错误,先不说这些,主要问下面的:
这点代码,无论是asp还是asp.net写,都不难.现在我主要是不知道怎么引用.在贴图区就是贴个路径,最后的页应是<IMG src="httP://www.111.com/img.asp?list=images">这样的代码怎么能执行后面的img.asp程序?请给出原理,我可以用net写img.aspx的代码或asp代码,共享出来,谢谢!
<%
'----------------------------------------------------------------------------------------
'转发时请保留松餍畔?这段声明不并会影响你的显示速度!
'************************* 随机图片显示 ****************************
'使用实例:img.asp?list=图片存放目录
'使用注意:图片目录放于本文件同目录下!需要FSO支持!
'说明:只要将变化图片放于一个目录下,修改下面程序的(需要修改的地方)成你的目录名称!
' 上传本程序和图片文件夹到同一目录下,在发帖时候使用UBB代码形如:即可!
'----------------------------------------------------------------------------------------
Function AllPath()
Dim Domain,GFilePath
Domain = Request.ServerVariables("SERVER_NAME")
GFilePath = Request.ServerVariables("PATH_INFO")
GFilePath = lcase(left(GFilePath,instrRev(GFilePath,"/")))
AllPath = "http://"&Domain&GFilePath
End Function
Function ShowFileList(folderspec)
Dim Path,objFSO,objFolder,count,objFile,nume,S
Path = Server.MapPath(folderspec)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(Path) Then
Set objFolder = objFSO.GetFolder(Path)
count = 0
For Each objFile in objFolder.Files
count = count+1
Next
randomize
nume = Int((count*rnd)+1)
S = 0
ShowFileList = ""
For Each objFile in objFolder.Files
S = S + 1
If S = nume Then
ShowFileList = objFile.Name
Exit For
End If
Next
Set objFolder = Nothing
Else
ShowFileList = "NO"
End If
Set objFSO = Nothing
End Function
Dim list,2004528115924.htm,address,str
list = trim(Request.QueryString("list"))
if list = "" then
Response.write "本页需要正确参数引入,您缺少相关的参数!正确格式如下:"&AllPath&"img.asp?list=(adpic)"
Response.End()
end if
2004528115924.htm = ShowFileList("./"&list&"/")
if 2004528115924.htm = "NO" then
Response.write "您指定的目录<b>"&list&"</b>不存在,请重新指定!"
Response.End()
end if
if 2004528115924.htm = "" then
Response.write "您指定的目录<b>"&list&"</b>没有相关的图片文件存在,请重新指定!"
Response.End()
end if
str = right(2004528115924.htm,3)
if str<>"jpg" and str<>"gif" then
2004528115924.htm = "erro.gif"
end if
address = AllPath&list&"/"
address = address&2004528115924.htm
%>
<%Response.redirect(address)%>以上的程序可能有错误,先不说这些,主要问下面的:
这点代码,无论是asp还是asp.net写,都不难.现在我主要是不知道怎么引用.在贴图区就是贴个路径,最后的页应是<IMG src="httP://www.111.com/img.asp?list=images">这样的代码怎么能执行后面的img.asp程序?请给出原理,我可以用net写img.aspx的代码或asp代码,共享出来,谢谢!
还是没明白???
比如在百度的贴吧,<IMG src="httP://www.111.com/img.asp?list=images">
它也不可能执行我的img.asp里的代码,如果能行,当然可以
我不是就在自己的的网上,<IMG src="httP://www.111.com/img.asp?list=images">是别人程序最后生成的页
Response.ContentType = "image/jpeg";
//直接输出某路径的图片
string path = "image/" + new Random().Next(0, 9) + ".jpg";
Response.WriteFile(path);
//结束程序
Response.End();如此而已。或者以Response.BinaryWrite(byte[] bytes)来输出二进制流。
这个标签不是你理解的那样一定是jpg、gif、bmp、png等后缀名,可以说是任何的,只要路径所指定的文件符合图片二进制格式。
如果这个路径所请求到的是一个asp或者是aspx页,那它会先执行程序代码,如果执行到最后输出的是图片二进制数据,那则正常显示出一个图片,否则就是一个显示不出图片的叉。我猜你可能是在这个上面有疑问吧,否则我就对你的疑问表示疑问了。
是这样吗?
是这样,您说对了.不过大家试过了吗>
代码不多,几分钟可搞定,
但不怎么试都不行,如:<IMG src="httP://www.111.com/img.asp?list=images">页面就最后是<IMG src="httP://www.111.com/img.asp?list=images">,如果是执行后面的代码,那么就简单了
比如
a.htm
<img src="img.asp">img.asp里产生个随机数然后。
Response.Redirect(随机数&".jpg")就可以了。
.net实现方法同。
<%
//随便设定一个路径,你要保证这个路径有个图片
string path = "images/x.gif";
//输出格式
Response.ContentType = "image/jpeg";
//输出文件
Response.WriteFile(path);
Response.End();
%>就是这么简单,下面这个也可以<%@ Page Language="c#"%>
<%
string path = "images/1.jpg";
System.Drawing.Image img = System.Drawing.Image.FromFile(path);
Response.ContentType = "image/jpeg";
img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
%>
<%
set connGraph=server.CreateObject("ADODB.connection")
connGraph.ConnectionString="driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.MapPath("db/db.mdb") &";uid=;PWD=;"
connGraph.Open
set rec=server.createobject("ADODB.recordset")
strsql="select pic from product where id=" & trim(request("id"))
rec.open strsql,connGraph,1,1
Response.ContentType = "image/*"
' 在输出到浏览器之前一定要指定Response.ContentType = "image/*",以便正常显示图片
Response.BinaryWrite rec("pic").getChunk(7500000)
rec.close
set rec=nothing
set connGraph=nothing
%>前面就是用
<img src="img.asp?id=<%=asp变量%>">
图片存在数据库里~~
hoho
<%Function AllPath()
Dim Domain,GFilePath
Domain = Request.ServerVariables("SERVER_NAME")
GFilePath = Request.ServerVariables("PATH_INFO")
GFilePath = lcase(left(GFilePath,instrRev(GFilePath,"/")))
AllPath = "http://"&Domain&GFilePath
End FunctionFunction ShowFileList(folderspec)
Dim Path,objFSO,objFolder,count,objFile,nume,S
Path = Server.MapPath(folderspec)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(Path) Then
Set objFolder = objFSO.GetFolder(Path)
count = 0
For Each objFile in objFolder.Files
count = count+1
Next
randomize
nume = Int((count*rnd)+1)
S = 0
ShowFileList = ""
For Each objFile in objFolder.Files
S = S + 1
If S = nume Then
ShowFileList = objFile.Name
Exit For
End If
Next
Set objFolder = Nothing
Else
ShowFileList = "NO"
End If
Set objFSO = Nothing
End FunctionDim list,filename,address,strlist = trim(Request.QueryString("list"))
if list = "" then
Response.write "本页需要正确参数引入,您缺少相关的参数!正确格式如下:"&AllPath&"img.asp?list=图片存放目录"
Response.End()
end iffilename = ShowFileList("./"&list&"/")
if filename = "NO" then
Response.write "您指定的目录<b>"&list&"</b>不存在,请重新指定!"
Response.End()
end ifif filename = "" then
Response.write "您指定的目录<b>"&list&"</b>没有相关的图片文件存在,请重新指定!"
Response.End()
end ifstr = right(filename,3)
if str<>"jpg" and str<>"gif" then
filename = "erro.gif"
end ifaddress = AllPath&list&"/"
address = address&filename
%>
<%Response.redirect(address)%>
封贴
<img src="a.aspx">就可以了呀