【php开源代码栏目提醒】:网学会员为需要php开源代码的朋友们搜集整理了random.php相关资料,希望对各位网友有所帮助!
<?php function RandomImage()
{
$randnum = 0;
print("<UL>\n");
//设置图片路径
$myDir = dir("./pics");
$icount = 1;
while($entryName = $myDir->read())
{
$icount++;
}
//关闭文件
$myDir->close();
$myDir = dir("./pics");
//倒回目录句柄
rewinddir();
//播下随机数发生器种子
srand(time());
$randnum = rand(3,($icount-2)+1);
//循环获取文件
for($i=0;$i<$randnum;$i++)
{
$entryName = $myDir->read();
$myimage = $entryName;
}
return('pics/' . $myimage);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD
HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
图片路径:<?php $picture = RandomImage(); ?>
<?php echo $picture;?><table width="250" height="237" border="2" cellpadding="0" cellspacing="3">
<tr>
<td><div align="center">循环预览图片 </div></td>
</tr>
<tr>
<td><img name="myImage" src="<?php echo $picture; ?>" width="360" height="215" alt=""></td>
</tr>
</table>
</body>
</html>