照片库-在每个目录文件夹中自动运行PHP和HTML


photo gallery - Run PHP and HTML automatically in every directory folder

我正在制作一个包含文件夹和图像子文件夹的照片库。我不想在每个文件夹中都放一个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>

谢谢你能提供的任何帮助。

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

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

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