Script to generate gallery from current directory

5,264

Solution 1

I found something :) Single File PHP Gallery. Demo here.

Solution 2

PhpGraphy should do the job.

If you do not want any installation try this:

<?php 
if ($handle = opendir('.')) {
    /* This is the correct way to loop over the directory. */
    while (false !== ($file = readdir($handle))) {
        $ext = end(explode('.', $file));
        if($ext == "jpg" || $ext == "png") {
            echo "<img src=\"$file\" alt=\"Image\" />";
        }
    }
    closedir($handle);
}
?>

Solution 3

A Very Simple PHP file that searches the current directory for jpg, png and gif files and puts it in a HTML <img> tag.

<?php
$format = '<img src="[FILE]"> [FILE]<br>';

chdir(dirname(__FILE__));

$files = glob("*.{jpeg,jpg,png,gif}", GLOB_BRACE);

foreach ($files as $file) {
    if (is_file($file)) {
        echo str_replace('[FILE]', htmlspecialchars($file), $format);
    }
}
?>

Nothing fancy, it shows all images after each other. Save it as index.php. Your webserver should support PHP and usually shows index.php for directories.

Share:
5,264

Related videos on Youtube

marioosh
Author by

marioosh

Updated on September 18, 2022

Comments

  • marioosh
    marioosh almost 2 years

    I'm searching for a small script (.php) that will generate a gallery from the current directory. I hope you know what I mean. Something like below. EDIT: I mean something that requires no installation, no configuration, etc. I need just put this script in the directory with images, open in web-browser and get simple gallery.

    /var/www/some/directory:

    a.jpg
    b.jpg
    c.jpg
    d.jpg
    gallery_script.php
    
  • marioosh
    marioosh about 13 years
    I was thinking of something simpler, no installation, no configuration etc. Just put in a directory and get image gallery.
  • marioosh
    marioosh about 13 years
    I can not download TStarGallery. tstar.taillandier.de/tstargallery/tstargallery10.rar = 403 Forbidden