设为首页   |  加入收藏夹 快速导航:  热门文章  |  最新文章  |  梦想博客  
当前位置:编程之家 -> 文章频道 ->php 
站内搜索:  

随机图片代码[PHP]

作者:佚名 来源:转载 整理日期:2006-06-21

<?php

$url=../images; //图片地址,只可以用./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]");

?>