首页 > 编程 > PHP > 正文

随机头像PHP版

2020-02-17 20:16:38
字体:
来源:转载
供稿:网友

1.  31字节 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]");

?>
上一篇:自动跳转中英文页面

下一篇:1.PHP简介

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表