« »

PHP:随机变化的.jpg图片

实现的原理很简单,就是apache的url_rewrite功能+php程序
url_rewrite代码

[test@test htdocs]$ cat .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^images/logo\.jpg$ /test/randomimg.php [L]
</IfModule>


php代码

  1. <?php 
  2. header("Content-Type: image/jpeg");
  3. $dir    = './images/';
  4.  
  5. $imgarr=array();
  6. if ($handle = opendir($dir)) { 
  7.     while (false !== ($file = readdir($handle))) { 
  8.         if (preg_match ("/(.*?)\.jpg$/i", $file) ) { 
  9.                 array_push($imgarr,$dir.$file);
  10.         } 
  11.     } 
  12.     closedir($handle);
  13. } 
  14. //srand ((float) microtime() * 10000000);
  15. readfile($imgarr[array_rand ($imgarr)]);
  16. ?>

只要把把要显示的图片放到$dir目录里就可以了:)

您还可能感兴趣的内容

日志信息 »

该日志于2008-11-22 13:11由 admin 发表在Apache, PHP分类下, 你可以发表评论。除了可以将这个日志以保留源地址及作者的情况下引用到你的网站或博客,还可以通过RSS 2.0订阅这个日志的所有评论。

没有评论

发表评论 »


返回顶部