当前位置:Linux教程 - Php - 生成随机图象的代码php的

生成随机图象的代码php的

生成随机图象的代码PHP的

作者:tdweb  时间:2004-05-02 19:21:33  来自:  责任编辑:clinch







  Code:    
<?php
/*
-------------------------------------------------------------
|MD 随机图象生成器  TDWEB汉化版                                 |
|版本 1.0.0                                              |
|版权所有 Matthew Dingley 2003  TDWEB [stt ]        |
|寻找更多MD软件的帮助信息,请登陆MD 网站:             |
|www.matthewdingley.co.uk                                   |
|following code into the page where you want the image:     |
|<?php include "image.php"; ?>                              |
-------------------------------------------------------------
*/
$dir=opendir("/home/you/public_html/folder/");
//This is the directory route to the folder
$directory="";
//This is a relative link to the directory if it is not in the same directory as the file you are displaying the images on

$pattern=".(gif|jpg|jpeg|png|bmp|swf)$";
if(!
$dir)
{
die(
"Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while(
$s)
{
if(
ereg($pattern, $s))
{
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);

//Spit it out
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$size=getimagesize("$directory$image[$randNum]");
echo
"<br><img src="$directory$image[$randNum]" $size[3]>";
?>