<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/ DTD/wml_1.1.xml">

<wml>
<head>
<meta http-equiv="cache-control" content="max-age=180,private" />
</head>
<card title="随机显示论坛头像代码">
<p>
作者:<a href="index.php?action=showuser&amp;userid=1&amp;hash=">admin</a><br />时间:2007-07-30 10:50<br />分类:<a href="index.php?action=list&amp;cid=3&amp;hash=">电脑技术</a><br />内容:
随机显示论坛头像代码


PHP随机显示论坛头像代码
第一种：
===============


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

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

第二种：
===================
&lt;?php
$url='pic';
$files=array();
if ($handle=opendir(&quot;$url&quot;)) { 
while(false !== ($file = readdir($handle))) { 
if ($file != &quot;.&quot; &amp;&amp; $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;);


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

第三种


&lt;?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; &amp;&amp; $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;);


?&gt;


ASP随机显示论坛头像代码


首先，用户使用本程序需要有自己的支持 ASP 的空间，同时还需要空间支持 FSO 组件。


使用方法如下：

1. 将本程序放知道支持 ASP 空间的某文件夹中，如 /SImage 路径。确保在 Internet 中能够访问到该程序。

2. 在本程序所在路径下，新建一个 Images 文件夹，你的一些自己喜欢的头像文件就放在这个文件夹中（支持 .jpg、.gif 和 .png 图片），此时图片就放在了 SImage/Images 下。

3. 在论坛的用户资料一栏中如下设置你的头像路径（需要开放头像链接引用功能，即允许使用第三方图片链接作为头像）： 

Snap1.gif (5.52 KB)
2007-4-16 13:51

Snap2.gif (2.08 KB)
2007-4-16 13:51

4. 程序代码（建议保存成 Default.asp）

[Copy to clipboard] [ - ]CODE:
&lt;%
Option Explicit
Dim Imgfolder,FSO,FD,F,OneFile,filename,file_arr,filename_arr0,iMax,ranNum,DataFolder,DataFileList,i

'On error resume next
Imgfolder=&quot;Images&quot;                 '设置头像文件存放的路径（相对于本程序）

Set FSO=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

IF Err&lt;&gt;0 Then
         Err.Clear
         Response.Write(&quot;服务器关闭FSO，无法查看备份文件列表&quot;)
Else
         Set DataFolder=FSO.GetFolder(Server.MapPath(Imgfolder))
         Set DataFileList=DataFolder.Files

         file_arr=file_list(Server.MapPath(Imgfolder))
         iMax=ubound(file_arr)
         randomize
         ranNum=int(iMax*rnd)
         Response.Redirect Imgfolder&amp;&quot;/&quot;&amp;file_arr(ranNum,0)
         Response.write Imgfolder&amp;&quot;/&quot;&amp;file_arr(ranNum,0)
End IF

Set FSO=Nothing

Function file_list(path)
         Set FSO=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
         Set FD=FSO.GetFolder(path)
         Set F=FD.Files
         For Each OneFile in F
                 filename=OneFile.Name
                 If LCase(right(filename,3))=&quot;jpg&quot; or LCase(right(filename,3))=&quot;gif&quot; or LCase(right(filename,3))=&quot;png&quot; Then
                         filename_arr0=filename_arr0&amp;filename&amp;&quot;|&quot;
                 End If
         Next
         filename_arr0=split(filename_arr0,&quot;|&quot;)

         dim filename_arr()
         redim filename_arr(ubound(filename_arr0),2)
         for i=0 to ubound(filename_arr0)-1
                 filename_arr(i,0)=filename_arr0(i)
         next
         erase filename_arr0
         file_list=filename_arr
End Function
%&gt;
注意事项：
1. 使用的图片，需要注意尺寸比例，多个不同图片放到一起，最好考虑将他们的尺寸比例改成一致的，因为有些论坛会自动识别头像尺寸的宽高比例，随机显示出来的图片可能会出现变形。
2. 图片的文件名需要注意，不要含有空格、乱码等。





</p><p>
<a href="index.php?action=login&amp;hash=">立即登陆发表评论</a><br />
</p>
<p><a href="index.php?action=list&amp;hash=">返回日志列表</a><br /><a href="index.php?action=index&amp;hash=">返回主页</a></p>
</card>
</wml>
