求百变图的原理及实现方法

lcy5415 2006-02-23 02:30:59
网上贴图区经常看到回复一次就变一次的贴子,觉得好玩,不明白其原理.后网上找一篇文章.讲原理是链到一个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代码,共享出来,谢谢!

...全文
193 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
iuhxq 2006-02-23
  • 打赏
  • 举报
回复
例如a.aspx是输出图片的,那直接
<img src="a.aspx">就可以了呀
lcy5415 2006-02-23
  • 打赏
  • 举报
回复
老了,写程序真不行了.搞定,是url错了,哈

谢谢各位,我早不玩程序了.兄弟们努力呀,实现方法其它简单.

怎么整都行,我给一下asp的,

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%

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,filename,address,str

list = trim(Request.QueryString("list"))
if list = "" then
Response.write "本页需要正确参数引入,您缺少相关的参数!正确格式如下:"&AllPath&"img.asp?

list=图片存放目录"
Response.End()
end if

filename = ShowFileList("./"&list&"/")
if filename = "NO" then
Response.write "您指定的目录<b>"&list&"</b>不存在,请重新指定!"
Response.End()
end if

if filename = "" then
Response.write "您指定的目录<b>"&list&"</b>没有相关的图片文件存在,请重新指定!"
Response.End()
end if

str = right(filename,3)
if str<>"jpg" and str<>"gif" then
filename = "erro.gif"
end if

address = AllPath&list&"/"
address = address&filename
%>
<%Response.redirect(address)%>


封贴
yiyioo 2006-02-23
  • 打赏
  • 举报
回复
img.asp

以前同事写过的
<%
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
underwater 2006-02-23
  • 打赏
  • 举报
回复
你该不会是问在论坛上写这个<img src='11.jpg'/>然后就真的显示出<img src='11.jpg'/>几个字符这种问题吧?
underwater 2006-02-23
  • 打赏
  • 举报
回复
asp我几年不写,不拿出来丢脸了,写段aspx你自己去测试,不对的自己改改,看你是否能明白吧

<%@ Page Language="c#"%>
<%
//随便设定一个路径,你要保证这个路径有个图片
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);
%>
zkxp 2006-02-23
  • 打赏
  • 举报
回复
加上引号看看
zkxp 2006-02-23
  • 打赏
  • 举报
回复
其实就是一个Response.Redirect
比如
a.htm
<img src="img.asp">

img.asp里产生个随机数然后。
Response.Redirect(随机数&".jpg")

就可以了。
.net实现方法同。
lcy5415 2006-02-23
  • 打赏
  • 举报
回复
我正在试,本地:<img src=img.aspx?list=mm/>

最后输出,还是<img src=img.aspx?list=mm/>

我的问题大家都明白了,看看我是否哪个地方没想明白,在线等结贴
luoyi107 2006-02-23
  • 打赏
  • 举报
回复
学习中...
lcy5415 2006-02-23
  • 打赏
  • 举报
回复
我猜你可能是在这个上面有疑问吧,否则我就对你的疑问表示疑问了。
是这样,您说对了.

不过大家试过了吗>
代码不多,几分钟可搞定,
但不怎么试都不行,如:<IMG src="httP://www.111.com/img.asp?list=images">

页面就最后是<IMG src="httP://www.111.com/img.asp?list=images">,如果是执行后面的代码,那么就简单了
underwater 2006-02-23
  • 打赏
  • 举报
回复
如果这个都无法理解,那怎么能理解验证码图片?
yiyioo 2006-02-23
  • 打赏
  • 举报
回复
<IMG src="httP://www.111.com/img.asp?list=images">

他自己会去找img.asp这个页面,找到了就自然会执行了

img.asp只要用request接受参数进行取值就可以了啊`


是这样吗?
underwater 2006-02-23
  • 打赏
  • 举报
回复
<img src='path' />
这个标签不是你理解的那样一定是jpg、gif、bmp、png等后缀名,可以说是任何的,只要路径所指定的文件符合图片二进制格式。
如果这个路径所请求到的是一个asp或者是aspx页,那它会先执行程序代码,如果执行到最后输出的是图片二进制数据,那则正常显示出一个图片,否则就是一个显示不出图片的叉。

我猜你可能是在这个上面有疑问吧,否则我就对你的疑问表示疑问了。
underwater 2006-02-23
  • 打赏
  • 举报
回复
拿.NET讲

//以二进制图片格式输出
Response.ContentType = "image/jpeg";
//直接输出某路径的图片
string path = "image/" + new Random().Next(0, 9) + ".jpg";
Response.WriteFile(path);
//结束程序
Response.End();

如此而已。或者以Response.BinaryWrite(byte[] bytes)来输出二进制流。
lcy5415 2006-02-23
  • 打赏
  • 举报
回复
每submit一次就换一下图片的链接不就行了吗
还是没明白???


比如在百度的贴吧,<IMG src="httP://www.111.com/img.asp?list=images">
它也不可能执行我的img.asp里的代码,如果能行,当然可以
我不是就在自己的的网上,<IMG src="httP://www.111.com/img.asp?list=images">是别人程序最后生成的页

jiezhi 2006-02-23
  • 打赏
  • 举报
回复
每submit一次就换一下图片的链接不就行了吗

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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