Home >php教程 >php手册 >随机取图的PHP代码

随机取图的PHP代码

WBOY
WBOYOriginal
2016-06-13 10:24:121164browse


// 用法
// include("ranimage.php");
// 或者
// require "ranimage.php";
$dir = DownloadFilesa2001-12-13;
function Get_Image_list($dir) {
if(!$dir) {
$dir = ".";
}
$file_array = array();
$dir_handle = opendir($dir);
$a = 0;
while($file = readdir($dir_handle)) {
if((preg_match(/jpg/,$file)) ||
(preg_match(/png/,$file)) ||
(preg_match(/gif/,$file)) ||
(preg_match(/jpeg/,$file))) {
$file_array[$a] = $file;
$a++;
}
}
return $file_array;
}
$files = Get_Image_list($dir);
$max = count($files)-1;
srand((double)microtime()*1000000);
$index = rand(0,$max);
$image_name = $files[$index];
echo("");
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:初探PHP5二Next article:判断oicq是否在线的php小程序