隨機(jī)頭像PHP版
發(fā)表時(shí)間:2024-01-25 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]1. 31字節(jié) PHP 隨機(jī)顯示頭像 <?readfile(rand(0,5).'.jpg');?>2.<?phpurl='pic';//圖片地址,用相對路徑files=array();if (handle=opendir("url&q...
1. 31字節(jié) PHP 隨機(jī)顯示頭像
<?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]");
?>