手机
当前位置:查字典教程网 >编程开发 >php教程 >php中随机显示图片的函数代码
php中随机显示图片的函数代码
摘要:例如博客的展示窗复制代码代码如下:

例如博客的展示窗

复制代码 代码如下:

<?php

/**********************************************

* Filename : img.php

* Author : freemouse

* web : www.cnphp.info

* email :freemouse1981@gmail.com

* Date : 2010/12/27

* Usage:

* <img src=img.php>

* <img src=img.php?folder=images2/>

***********************************************/

if($_GET['folder']){

$folder=$_GET['folder'];

}else{

$folder='/images/';

}

//存放图片文件的位置

$path = $_SERVER['DOCUMENT_ROOT']."/".$folder;

$files=array();

if ($handle=opendir("$path")) {

while(false !== ($file = readdir($handle))) {

if ($file != "." && $file != "..") {

if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;

}

}

}

closedir($handle);

$random=rand(0,count($files)-1);

if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");

elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");

readfile("$path/$files[$random]");

?>

【php中随机显示图片的函数代码】相关文章:

高亮度显示php源代码

php生成图片验证码

综合图片计数器

写一个用户在线显示的程序

php筛选不存在的图片资源

php实现随机显示图片方法汇总

PHP滚动日志的代码实现

php中smarty区域循环的方法

php eval函数一句话木马代码

php一个解析字符串排列数组的方法

精品推荐
分类导航