22 07年3月

随机变化的.jpg图片

关键字:, ,
贝贝爸 发表在 原创技术文章 |

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

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

php代码

  1. <?php
  2. /*
  3. * Created on 2007-3-20
  4. *
  5. * To change the template for this generated file go to
  6. * Window - Preferences - PHPeclipse - PHP - Code Templates
  7. */
  8. header("Content-Type: image/jpeg");
  9. $dir    = './images/';
  10.  
  11. $imgarr=array();
  12. if ($handle = opendir($dir)) {
  13.     while (false !== ($file = readdir($handle))) {
  14.         if (preg_match ("/(.*?)\.jpg$/i", $file) ) {
  15.                 array_push($imgarr,$dir.$file);
  16.         }
  17.     }
  18.     closedir($handle);
  19. }
  20. //srand ((float) microtime() * 10000000);
  21. readfile($imgarr[array_rand ($imgarr)]);
  22. ?>

只要把把要显示的图片放到
$dir目录里就可以了:)
效果点击这里,或者刷新本页面,看右上角的图片。

“随机变化的.jpg图片”2个评论

请添加你的评论!您的观点很重要,来吧,让贝贝知道你想的是啥。

  1. 1 On 2007年3月23 6:35, Ken说:

    呵呵,我就说是用这个。。。

  2. 2 On 2007年3月23 8:46, 贝贝爸说:

    :)

发表评论

美体小铺急救棒 the bodyshop body shop 美体小铺茶树精油 美体小铺接骨木花眼胶 美体小铺VE眼霜
美体小铺急救棒 the bodyshop body shop 美体小铺茶树精油 美体小铺接骨木花眼胶 美体小铺VE眼霜