Home > Backend Development > PHP Tutorial > PHP code for randomly fetching images_PHP tutorial

PHP code for randomly fetching images_PHP tutorial

WBOY
Release: 2016-07-13 17:23:52
Original
753 people have browsed it


// 用法
// 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("PHP code for randomly fetching images_PHP tutorial");
?>

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 =...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template