Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 520479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:08:58+00:00 2026-05-13T08:08:58+00:00

Hey all, my first post :D Problem: I’m trying to make a template gallery,

  • 0

Hey all, my first post 😀

Problem:

I’m trying to make a template gallery, not a slide show, which i can easily reuse on multiple sites.
Mostly for quick folio sites, where the owner wont know how to update the code to add pictures.

It needs to read all of the image files from a selected directory. (jpg, gif, png, bmp)
It needs to be able to update content without any code changes. (dynamic load from folder)
It needs to write out img tags to the viewed page. (using JavaScript for customization/css?)

The set of img tags output from the php/JavaScript need to be thumbnails which when clicked will link to the full def pictures, this can probably be handled with JavaScript when making the links initially.

Progress:

I found a php script that will read the files from a folder and save the urls to an array for use in JavaScript.
However the code used to display the picture is done as a single block slide show, where as i need it to post all images separately not just replace the src of the same image.

Example:

root/index.htm – pastebin[.]com/m52568ed5
root/images/getimages.php – pastebin[.]com/f5395a572
root/images/pic01.png
root/images/pic03.jpg
root/images/asdfs.gif

So how do i get JavaScript to loop through the galleryarray[curimg] and write out my links?

I got this far, and got stuck.

function rotateimages(){
 // document.getElementById("slideshow").setAttribute("src", "res/gallery/painting/"+galleryarray[curimg])
 // curimg=(curimg<galleryarray.length-1)? curimg+1 : 0
 for (curimg=1;curimg!=0;curimg++;) {
 document.write("<div><img class='gallery' src='" + galleryarray[curimg] + "' /></div>")
 }
}

Thanks in advance, Braden.


EDIT:
heres my sandbox to show whats going on

-EDIT: removed link

No matter how i change the output per item for example if i replace the whole section with a simple echo all i ever get is the following:

<!DOCTYPE html>
<html>
    <head>
        <title>My Gallery</title>
    </head>

    <body>
        <div id="gallery"></div>
    </body>
</html>

Seems like it gets stuck when it tries to run the ‘foreach()’

Heres the current php:

<?php

function getDirTree($dir,$p=true) {
    $d = dir($dir);$x=array();
    while (false !== ($r = $d->read())) {
        if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
                $x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
        }
    }

    foreach ($x as $key => $value) {
        if (is_dir($dir.$key."/")) {
                $x[$key] = getDirTree($dir.$key."/",$p);
        }
    }

    ksort($x);
    return $x;
}

$tree = getDirTree("./res/gallery/");

echo '<div id="gallery">';

foreach($tree as $element => $eval) {
    if (is_array($eval)) {

        foreach($eval as $file => $value) {
                if (strstr($file, "jpg")) {
                        $file = 'res/gallery/'.$element.'/'.$file;
                        echo 'test'; //test//echo '<a href="'.$file.'">test</a>'; //test// <img class="gallery" src="'.$file.'" alt="'.$file.'"/></a>';
                }
        }


    }
}
echo '</div>';

considering as i have Never done php before i started this, i think im doing ok.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:08:59+00:00Added an answer on May 13, 2026 at 8:08 am

    Very simple auto gallery script, photos.php:

    <?php
    function getDirTree($dir,$p=true) {
        $d = dir($dir);$x=array();
        while (false !== ($r = $d->read())) {
            if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true)) {
                $x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
            }
        }
    
        foreach ($x as $key => $value) {
            if (is_dir($dir.$key."/")) {
                $x[$key] = getDirTree($dir.$key."/",$p);
            }
        }
    
        ksort($x);
        return $x;
    }
    
    $tree = getDirTree("./foto/");
    
    echo '<div id="gallery">';
    echo '<ul class="linone">';
    foreach($tree as $element => $eval) {
        if (is_array($eval)) {
            echo '<li><h4>'.$element.'</h4>';
            echo '<ul class="linone photos">';
            foreach($eval as $file => $value) {
                if (strstr($file, "jpg")) {
                    $file = 'foto/'.$element.'/'.$file;
                    echo '<li><a href="'.$file.'"><img src="'.$thumb.'" alt="'.$thumb.'"/></a></li>';
                }
            }
            echo '</ul>';
            echo '</li>';
        }
    }
    echo '</ul>';
    echo '</div>';
    

    Also I use the lightbox jQuery plugin to make this gallery comfortable to view.

    And also managing photos for this page is very-very simple – you just need to upload .jpg files to your photos directory (‘/foto/’, for this example).

    index.php:

    <!DOCTYPE html>
    <html>
        <head>
            <title>My Gallery</title>
        </head>
    
        <body>
            <?php require_once('photos.php') ?>
        </body>
    </html>
    

    This file will include photos.php file and runs it, output of photos.php script will come between tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all I'm trying to make a 3d game in with 2d sprite characters.
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
Hey all, first post and a noob in Android programming, but willing to learn!
hey all, i have a question about urlmapping in grails. I'm trying to make
First of all I'm trying to learn regex so if it can be better,
Hey all this is the first time i am calling a stored procedure via
Hey all, i am trying to replace large spaces between text with just one.
Hey all. Trying to get a little more efficient with lists in Python but
Hey all, i am trying to get my bottom bar to center on the
Hey all, I'm trying to write a sort function but am having trouble figuring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.