当前位置:Gxlcms > PHP教程 > 随机头像PHP版_PHP

随机头像PHP版_PHP

时间:2021-07-01 10:21:17 帮助过:81人阅读

1. 31字节 PHP 随机显示头像




2.

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

?>

人气教程排行