Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.


share|improve this question

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

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


$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:

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\" />";
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. = 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


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.