求每次打开都会变成不一样的图片的代码

来源:百度知道 编辑:UC知道 时间:2024/05/14 05:06:15
求每次打开都会变成不一样的图片的代码 5个图片随机显示就可以 谁有阿 谢谢了!

<?php

$url='./logo'; //图片地址,只可以用./you/images这样的路径

$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]");

?>

可能没有的那。。。。。。。