0

I'm making a photo gallery with folders and subfolders of images. I'd like to not have to put an HTML file in every folder. How can this be done? Here is my 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";
}

?>

And here is my HTML:

<body>

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

</body>

Thanks for any help you can give.

  • Why would you need an HTML file in every folder? – Pitchinnate Feb 18 '13 at 15:15
  • I'm just looking for a way to do a photo gallery directory. Here's where I'm at so far. When you click a an image in the "PHP Images", it opens the folder but there isn't an index file so it gives an error. Any thoughts? – dougburnett Feb 18 '13 at 21:53

1 Answers1

0

You could use htaccess to map every file to your php code:

Options +FollowSymLinks

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

This shows the old image url in the browser bar, but internally calls your php script. Im not quite shure what your trying exactly. You could also have a rewrite for a existing folder and sent that to your script. For a more exact answer we need more informations on where files do live on your server.

Julian Hille
  • 669
  • 5
  • 11