【问题标题】:Run PHP and HTML automatically in every directory folder在每个目录文件夹中自动运行 PHP 和 HTML
【发布时间】:2013-02-18 15:13:06
【问题描述】:

我正在制作一个包含图像文件夹和子文件夹的照片库。我不想在每个文件夹中都放一个 HTML 文件。如何才能做到这一点?这是我的 PHP:

<?php

$directory = "thumbs/";
$files = glob($directory."*");
$photoCount = 0;

buildStage();

function buildStage() {
    global $directory, $files;

    foreach($files as $file) {
        if(is_dir($file)) showFolder($file);
        else showPhotos($directory);    
    }
}

function showPhotos($imagePath) {
    global $photoCount;
    $imageFile = glob($imagePath."/*.*");
    echo '<img src="'.$imageFile[$photoCount].'" id="thumbPic"
            onmouseover="imageOver(this)" 
            onmouseout="imageOut(this)" 
            />'."\n";
    $photoCount++;
}

function showFolder($imagePath) {
    $imageFile = glob($imagePath."/*.*");
    echo '<a href="' .$imagePath. '<img src="'.$imageFile[1].'"  id="folder"
            onmouseover="imageOver(this)" 
            onmouseout="imageOut(this)" 
            onmousedown="imageDown(this)"
            />'."\n";
}

?>

这是我的 HTML:

<body>

<div id="container">
<?php include 'jellybox.php'; ?>
</div>

</body>

感谢您提供的任何帮助。

【问题讨论】:

  • 为什么每个文件夹都需要一个 HTML 文件?
  • 我只是在寻找一种方法来制作照片库目录。这就是我目前所处的位置。当您单击“PHP 图像”中的图像时,它会打开文件夹但没有索引文件,因此会出错。有什么想法吗?

标签: php photo-gallery


【解决方案1】:

您可以使用 htaccess 将每个文件映射到您的 php 代码:

Options +FollowSymLinks

RewriteEngine On
RewriteBase /dependsOnyourPathes/
RewriteRule ^[images|thumb]/(.+).jpg$  script.php?file=$1.pdf [L,NC,QSA]

这会在浏览器栏中显示旧图像 url,但会在内部调用您的 php 脚本。 我不太确定你到底在尝试什么。你也可以重写 现有文件夹并将其发送到您的脚本。要获得更准确的答案,我们需要有关文件在您的服务器上的位置的更多信息。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2011-07-07
  • 1970-01-01
  • 1970-01-01
  • 2014-06-26
  • 2016-02-17
  • 2018-12-26
  • 1970-01-01
  • 2020-11-22
相关资源
最近更新 更多