当前位置: 移动技术网 > IT编程>开发语言>.net > 用ASP实现刷新一次换一张图片

用ASP实现刷新一次换一张图片

2018年10月07日  | 移动技术网IT编程  | 我要评论

观赏鱼之家网站,苏州周边自驾游,国家主席现在是谁

    看到别人网站中每次刷新都能看到不同的广告图片,是不是很羡慕啊?没关系啦,下面我们就来看一下如何用asp实现刷新一次换一张图片:

<%@language="vbscript" codepage="936"%>
<%@response.buffer=false%>
<%
用asp实现刷新一次换一张图片
’代码设计 by iceworld
’说明:
’1:可以不加参数实现刷新一次换一次图片,也可以用index.?img=图片名字来显示指定的网页
’2:同上面的代码,加入了错误处理
’由于本人学习asp时间不长,有错误的话,还希望高手不吝赐教
imagepath=server.mappath("image")
’定义图片的文件夹

num=0
’num变量表示图片的个数
total=0
’total变量表示文件夹内部所有文件的个数
set fso=server.createobject("scripting.filesystemobject")
’创建fso对象
if not fso.folderexists(imagepath) then
response.write("指定的图片文件夹不存在!")
response.end()
end if
’判断文件夹是否存在
img=request.querystring("img")
if img<>"" then
imgpath=imagepath& "/" &img
if not fso.fileexists(imgpath) then
response.write("对不起,您指定的图片没有找到!")
response.end()
end if
’如果有img变量,则判断该图片是否存在
else
set fileall=fso.getfolder(imagepath).files
for each d in fileall
if right(d.name,3)="bmp" or right(d.name,3)="gif" or right(d.name,3)="jpg" or right(d.name,3)="png" then
num=num+1
end if
total=total+1
next
’搜集一下图片和文件的总个数,得到变量num和total的值,可自己添加知道的图片后缀
if total=0 then
response.write("文件夹存在,但是没有任何文件!")
response.end()
end if
’当文件夹为空的时候
if num=0 then
response.write("虽然文件夹里面有文件,但是图片文件的个数为0!")
response.end()
end if
’当文件夹内部没有图片的时候
randomize
a=int(num*rnd+rnd)
for each d in fileall
if right(d.name,3)="bmp" or right(d.name,3)="gif" or right(d.name,3)="jpg" or right(d.name,3)="png" then
if rnnd=a then
imgpath=d.path
exit for
else
rnnd=rnnd+1
end if
end if
next
end if
’随即产生图片
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>用asp实现刷新一次换一张图片</title>
</head>

<body>
<%
if img="" then
%>
该文件夹内部共有文件<%=total%>个,其中图片有<%=num%>个,下面是随机产生的图片:
<%
else
%>
下面是你所提交的图片:
<% 
end if 
%><br><p align="center"> 
<img name="imagee" src="<%=imgpath%>" width="355" height="308" alt=""> </p> 
</body> 
</html> 
<% 
set fileall=nothing 
set fso=nothing 
%> 

技术交流 永无止境

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网