【发布时间】:2015-06-02 22:46:13
【问题描述】:
我想让我的横幅像幻灯片一样自动更改。我从文件夹中取出的横幅,它可以读取该文件夹中的所有横幅并在网站上显示它会自动更改。我已经让它阅读所有横幅并将其显示在网站上,但它是一种随机图像,除非我重新加载页面,否则不会改变。这是代码:
<?php
$imglist='';
//$img_folder is the variable that holds the path to the banner images.
// see that you dont forget about the "/" at the end
$img_folder = "images/";
mt_srand( (double)microtime()*1000 );
//use the directory class
$imgs = dir($img_folder);
//read all files from the directory, checks if are images and ads them to a list (see below how to display flash banners)
while ( $file = $imgs->read() )
{
if (eregi("gif", $file) || eregi("jpg", $file) || eregi("png", $file))
$imglist .= "$file ";
}
closedir($imgs->handle);
//put all images into an array
$imglist = explode(" ", $imglist); $no = sizeof($imglist)-2;
//generate a random number between 0 and the number of images
$random = mt_rand(0, $no); $image = $imglist[$random];
//display image
echo '<img class="img-responsive" src="'.$img_folder.$image.'" border=0>';
?>
以及如何将 PHP 转换为 HTML?如果我将扩展名更改为 html,则横幅 div 会显示代码而不是图像。谢谢。
【问题讨论】:
标签: javascript php jquery html slideshow