风讯官方论坛

首页 » FoosunCMS交流区 » 插件讨论 » 刷新一次变一次图片的代码[PHP和ASP](经典
zzcszzcs - 2007-6-24 16:12:00
PHP的
首先建个pic文件夹

然后随意建个后缀为php的文件,把以下代码加入,代码如下:

<?php
$url='pic';
$files=array();
if ($handle=opendir("$url")) {
  while(false !== ($file = readdir($handle))) {
      if ($file != "." && $file != "..") {
      if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
      }
  }
}
closedir($handle);
$random=rand(0,count($files)-1);
readfile("$url/$files[$random]");

?>


上传多张图片放入pic文件夹中

访问:你的地址+建立的随意的.php文件

效果:http://www.letianpai.com/pic.php

或者刷新看我签名


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&"pic.asp?list=pic"
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)%>

访问的正确格式应为:"&AllPath&"pic.asp?list=pic"后面的pic改成文件夹名即可!

演示:http://www.letianpai.com/pic.asp?list=pic

ASP的必须调用才行,不可直接打开
1
查看完整版本: 刷新一次变一次图片的代码[PHP和ASP](经典