当前位置:Gxlcms > PHP教程 > 随机取图的PHP代码_PHP教程

随机取图的PHP代码_PHP教程

时间:2021-07-01 10:21:17 帮助过:4人阅读

// 用法
// 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("");
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/532193.htmlTechArticle// 用法 // include("ranimage.php"); // 或者 // require "ranimage.php"; $dir = DownloadFilesa2001-12-13; function Get_Image_list($dir) { if(!$dir) { $dir = "."; } $file_array =...

人气教程排行