实现的原理很简单,就是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代码
<?php
/*
* Created on 2007-3-20
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
header("Content-Type: image/jpeg");
$dir    = './images/';
 
$imgarr=array();
if ($handle = opendir($dir)) {
    while (false !== ($file = readdir($handle))) {
        if (preg_match ("/(.*?)\.jpg$/i", $file) ) {
                array_push($imgarr,$dir.$file);
        }
    }
    closedir($handle);
}
//srand ((float) microtime() * 10000000);
readfile($imgarr[array_rand ($imgarr)]);
?> 
只要把把要显示的图片放到
$dir目录里就可以了:)
效果点击这里,或者刷新本页面,看右上角的图片。
《 “随机变化的.jpg图片” 》 有 2 条评论
🙂
呵呵,我就说是用这个。。。