欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

随机取图的PHP代码

程序员文章站 2022-04-18 21:33:44
...
// 用法
// 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("");
?>