PHP构建图库导航

PHP构建图库导航,php,javascript,jquery,html,ajax,Php,Javascript,Jquery,Html,Ajax,我想知道是否有可能使用我的服务器的文件结构来自动构建图像库的导航菜单。 目前,我有一个简单的“showcase”,带有指向不同图像文件夹的硬编码链接(使用jquery、ajax和php,有些东西我不太了解,但从教程等中学习了如何使用)。基本上,我有三个文件: main.php main.css images.php 我使用main.php上的硬链接调用images.php脚本,将包含图像的特定文件夹加载到主页上的div中 以下是我当前的导航设置: <ul> <li

我想知道是否有可能使用我的服务器的文件结构来自动构建图像库的导航菜单。 目前,我有一个简单的“showcase”,带有指向不同图像文件夹的硬编码链接(使用jquery、ajax和php,有些东西我不太了解,但从教程等中学习了如何使用)。基本上,我有三个文件:

  • main.php
  • main.css
  • images.php
我使用main.php上的硬链接调用images.php脚本,将包含图像的特定文件夹加载到主页上的div中

以下是我当前的导航设置:

 <ul>
    <li><a href="#" onclick="loadPage('images.php?dirname=images/animals')">Animals</a></li>
    <li><a href="#" onclick="loadPage('images.php?dirname=images/people')">People</a></li>
    <li><a href="#" onclick="loadPage('images.php?dirname=images/objects')">Objects</a></li>
</ul>
我的问题是:既然我的所有图像都在“images”目录下的子目录中,那么有没有一种方法可以使用“images”中子目录的名称构建导航点(php脚本?)?(以便在我添加更多文件夹时保持最新)


此外,由于某些原因,我无法使脚本中的变量包含“images.php?dirname=images/”,是否有办法解决此问题?

如果它们都在
images
目录中,您可以指定
$images\u路径

<?php
$image_path = '/full/path/to/images';
if ($_GET['gallery']) {
    $gallery_path = $image_path . '/' . $_GET['gallery'];

    # if $_GET['gallery'] is `animals`:
    # 
    # $gallery_path = '/full/path/to/images/animals'

    # load your images within this path
}
?>

并使用



dir示例没有包含在答案中,答案现在就在那里。这将获得指定目录中所有子目录的列表。现在如何忽略该子目录。和。。文件夹?更新为
if(($entry!='.)| |($entry!='..){…}
<?php
$image_path = '/full/path/to/images';
$d = dir($image_path);
while (false !== ($entry = $d->read())) {
    if (is_dir($image_path . $entry)) {
        if (($entry != '.') || ($entry != '..')) {
            echo $entry; # or print your html code for each directory.
        }
    }
}
?>