广告联盟网

标题: PHP随机显示论坛头像代码 [打印本页]

作者: 总代    时间: 2006-1-6
标题: PHP随机显示论坛头像代码
第一种:
===============


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

?>
作者: 血饕餮    时间: 2006-1-6
不错哦,收藏




欢迎光临 广告联盟网 (https://www.ggads.com/) Powered by Discuz! X3.2