Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > Random Image Script
【标  题】:Random Image Script
【关键字】:Random,Image,Script
【来  源】:http://www.cublog.cn/u/712/showart.php?id=102988

Random Image Script

Your Ad Here

Description

This is your standard random image script that takes a slightly different approach than most, namely using standard HTTP headers instead of reading the file through the script.

Installation/Usage

For the simplest possible installation, just drop this code in a directory with the images you want to rotate, and call it like you would a normal image, for example:

<img src="/dropbox/2003/rotate/rotate.php" alt="A Random Image" />


Code

A Rotator Apart

<?php
/*
    By Matt Mullenweg > http://photomatt.net
    Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
    Latest version always at:
    http://photomatt.net/scripts/randomimage
*/

// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = '';

// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';

$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';

$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
    foreach($exts as $ext) { // for each extension check the extension
        if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
            $files[] = $file; // it's good
            ++$i;
            }
        }
    }
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along

header('Location: '.$folder.$files[$rand]); // Voila!
?>

Notes

For additional information about the thinking behind this script, see A Better Image Rotator


http://photomatt.net/scripts/randomimage




$exts = 'jpg jpeg png gif';

$exts = explode(' ', $exts);

只是查看有没有以jpg jpeg png gif后缀的文件,比较笨,没看具体文件格式
echo:【上一篇】
python内建函数(系列原创)(翻译):【下一篇】
【相关文章】
  • 对Array对象的错误认识[Action Script]
  • ActionScript
  • Action Script事件
  • 常用的几个javascript语句
  • Multiple actions in Sieve script.
  • jscriptpatch.cpp-IE漏洞补丁
  • a perl script automatic make a cppunit test case
  • STRUTS下几种IMAGE标签的使用以及区别
  • javascript数组运用-解决多个单选框状态检查
  • javascript代码收集
  • 【随机文章】
  • 使用Web Service Interface.
  • 架构设计中的方法学(1)——方法源于恐惧(2)
  • 跨平台开发连载(2_线程基类)
  • 转载:C/C++深层探索(四)
  • [转载]gis行业的定位
  • PC安装OS X系统安装说明(G)
  • KM实施方法论之六:知识管理的实施原则
  • 语音压缩及IP网上话音(VoIP)技术
  • javascript哪位高手帮我解决这个程序的光标定位问题???
  • 使用紧急恢复盘修复系统
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.