广告联盟网

 找回密码
 注册
查看: 667|回复: 1
打印 上一主题 下一主题

PHP随机显示论坛头像代码

[复制链接]
跳转到指定楼层
1#
发表于 2006-1-6 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
第一种:
===============


QUOTE:

<?=readfile(&quot;./img/&quot;.rand(1,4).&quot;.jpg&quot;)?>

===========
上面另存为php文件。传到目录上,在此目录下建个“ img&quot;文件夹,把1 2 3 4 的jpg 或者 gif 文件放到这里。

第二种:
===================


QUOTE:

<?php
$url='pic';
$files=array();
if ($handle=opendir(&quot;$url&quot;)) {
while(false !== ($file = readdir($handle))) {
if ($file != &quot;.&quot; && $file != &quot;..&quot;) {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
}
}
}
closedir($handle);
$random=rand(0,count($files)-1);
readfile(&quot;$url/$files[$random]&quot;);

?>

==================
使用方法:
将此文件放在某目录下,先在控制面板中改你头像图片的地址为此文件地址,然后在该目录下创建目录pic,将所有图片放在目录pic下即可

第三种


QUOTE:

<?php

  $path='/virtual/www.fd.fj.cn/face/gif/';//图片目录绝对路径
  $files=array();
  if ($handle=opendir(&quot;$path&quot;)) {
      while(false !== ($file = readdir($handle))) {   
                if ($file != &quot;.&quot; && $file != &quot;..&quot;) {
                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(&quot;Content-type: image/gif&quot;);
  elseif(substr($files[$random],-3)=='jpg') header(&quot;Content-type: image/jpeg&quot;);
  readfile(&quot;$path/$files[$random]&quot;);

?>
2#
发表于 2006-1-6 | 只看该作者
不错哦,收藏
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|广告联盟网  

GMT, 2024-5-10 , Processed in 0.042705 second(s), 19 queries .

Powered by Discuz! X3.2

© 2005-2021 www.ggads.com GGADS 广告联盟网

快速回复 返回顶部 返回列表