当前位置:首页> PHP教程> php基础
关键字
文章内容
随机头像PHP版
 
 
修改时间:[2009/09/02 06:05]    阅读次数:[786]    发表者:[起缘]
 
节 PHP 随机显示头像
<?readfile(rand(0,5).'.jpg');?>
2.
<?php
$url='pic';
//图片地址,用相对路径
$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]");
?>
phpfans.net收集整理