PHP随机显示图像代码

发表于:2007-06-21来源:作者:点击数: 标签:

   
  代码:
<?php

$url='./';
//图片地址,用相对路径

$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);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
readfile("$url/$files[$random]");

?>

原文转自:http://www.ltesting.net