在html中使用php向幻灯片添加图像

在html中使用php向幻灯片添加图像,php,html,Php,Html,我正在试着调整本地足球俱乐部的电视屏幕节目。我已经使网站工作,但现在我想让它更加用户友好 具体来说,我想让网站工作,以便有人可以只添加图像到某个文件夹,幻灯片将使用文件夹中的所有图像 守则的有关部分如下:;请注意,图像是硬编码的: <html> <head> <script type="text/javascript" src="js/tabs.js"></script> <script src="js

我正在试着调整本地足球俱乐部的电视屏幕节目。我已经使网站工作,但现在我想让它更加用户友好

具体来说,我想让网站工作,以便有人可以只添加图像到某个文件夹,幻灯片将使用文件夹中的所有图像

守则的有关部分如下:;请注意,图像是硬编码的:

<html>
    <head>
        <script type="text/javascript" src="js/tabs.js"></script>
        <script src="js/jquery.js"></script>
        <link rel="stylesheet" type="text/css" href="css/style.css">
        <script type="text/javascript" src="js/slider.js"></script>
    </head>
    <body>
        <div class="corner_1">
            <?php include("inc/script.php"); ?>
        </div>
        <div class="slider" id="slider">
            <ul>
                <li style="background-image:     url('http://homedir.com/images/IMG_4947.JPG'); no-repeat center center fixed; 
   background-repeat: no-repeat;
      background-size: 100% 100%;
    background-position: center top;
    background-attachment: fixed;">
                </li>
                <li style="background-image:     url('http://homedir.com/images/IMG_4939.JPG'); no-repeat center center fixed; 
   background-repeat: no-repeat;
      background-size: 100% 100%;
    background-position: center top;
    background-attachment: fixed;">
                </li>
                <li style="background-image:     url('http://homedir.com/images/IMG_4922.JPG'); no-repeat center center fixed; 
   background-repeat: no-repeat;
      background-size: 100% 100%;
    background-position: center top;
    background-attachment: fixed;">
                </li>
            </ul> 
        </div>
    </body>
    </html>

我试图用PHP中的glob()和echo函数制作一些东西,但无法使其工作。

您可以很容易地执行
scandir()

# I am just going to use this to clean up the html, you don't have to do this...
$style = array(
    'background: no-repeat center center fixed',
    'background-repeat: no-repeat',
    'background-size: 100% 100%',
    'background-position: center top',
    'background-attachment: fixed'
);
$style = implode('; ',$style);
# I use a define('ROOT_DIR',__DIR__) in a root-based config file to get the full path
$path = '/var/www/vhosts/domain/images';
# Scan the directory
$dir  = scandir($path);
# Loop through files in directory
foreach($dir as $file) {
    # Use our root path to make sure file exists
    # (there are . and .. that will be in the array
    if(!is_file($path.'/'.$file))
        continue;
?>
        <li style="background-image: url('http://homedir.com/images/<?php echo $file ?>'); <?php echo $style ?>">
        </li>
<?php
}
#我只是想用它来清理html,你不必这么做。。。
$style=数组(
'背景:无重复中心固定',
'背景重复:无重复',
“背景大小:100%100%”,
'背景位置:中间顶部',
'背景附件:已修复'
);
$style=内爆(“;”,$style);
#我在一个基于根的配置文件中使用define('ROOT\u DIR',\uu DIR\uuu)来获取完整路径
$path='/var/www/vhosts/domain/images';
#扫描目录
$dir=scandir($path);
#循环浏览目录中的文件
foreach($dir作为$file){
#使用根路径确保文件存在
#(数组中有.和..)
如果(!is_file($path.'/'.$file))
继续;
?>

你确定这是正确的吗?我得到了一个意外的EOF错误。正确的方法?语法方面?语法正确。你应该得到一个带有以下行的数组:
$dir=scandir($path);
。你必须确保
$path
是有效的。你可以使用
echo(is_dir($path))?“有效的”:“无效的”;退出;
来检查目录是否存在。