随机变化的.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代码

<?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&#91;array_rand ($imgarr)&#93;);
?> 

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


《“随机变化的.jpg图片”》 有 2 条评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据