Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|improve this question

4 Answers 4

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|improve this answer

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);
}
?>
share|improve this answer
    
I was thinking of something simpler, no installation, no configuration etc. Just put in a directory and get image gallery. –  marioosh Jun 18 '11 at 14:11

TStarGallery seems to be exactly what you want. If you want something a little more configurable, something like Gallery would require a bit more work to set up, but reward you with more options.

share|improve this answer
    
I can not download TStarGallery. tstar.taillandier.de/tstargallery/tstargallery10.rar = 403 Forbidden –  marioosh Jun 18 '11 at 14:26
up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.