Home  >  Article  >  php教程  >  随机头像PHP版

随机头像PHP版

WBOY
WBOYOriginal
2016-06-13 12:43:57808browse


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

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Content-type 的说明Next article:正则表达式语法