1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

display all images in a folder - help needed

Discussion in 'Web Design & Development' started by gurutech, Dec 21, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. gurutech

    gurutech Thread Starter

    Joined:
    Apr 23, 2004
    Messages:
    2,960
    I'm trying to write a quick php or html code that will scan a specific folder on my website and display these files.

    File names won't change, but each of the images is a PNG file with text (which changes) written over the image via apache "rewrite" code.

    Each time I pull up an individual image file, everything works fine. But I would like to have a single page that will "pull up" all of the PNG files in a single folder (about 10-15 images total).

    With the code I have, I just get a blank screen. I'm using the "foreach" and "glob($dir.$filename)" functions, if that helps.

    Can someone point me in the right direction to get this working?
     
  2. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,393
    First Name:
    Jim
    Hi there I actually use the following script to display car photo uploads which can can be jpg, gif or png, but you can adapt it for your own requirements, I'm sure...
    PHP:
    $photo_dir "FU/server/php/files/" $id "/medium/";
    if (
    is_dir($photo_dir))
    {
        if (
    $handle opendir($photo_dir)) 
        {
            while (
    false !== ($entry readdir($handle))) 
            {
                if (
    $entry[0] != ".")
                {
                    echo 
    "<td><a href=\"./Gallery.php?id=$id&pic_id=$pic_id\" onclick=\"window.open('./Gallery.php?id=$id&pic_id=$pic_id' ,'popup','width=800,height=750,scrollbars=no,resizable=yes,toolbar=yes,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false\"><img src=\"$photo_dir$entry\" class=\"upped\" title=\"Click to view Gallery...\" alt=\"Large Car Pic\" width=\"640\" /></a></td>";
                    break;
                }
            }
            
    closedir($handle);
        }
    }
    in each windows directory there are a couple of control files called . and .. - that is the reason for the check on the first character of the name of the file.
     
  3. gurutech

    gurutech Thread Starter

    Joined:
    Apr 23, 2004
    Messages:
    2,960
    I'm actually looking for the script to display the image file itself, not the name of the image file in a directory type listing.

    Here's what I have so far:

    Code:
     <html>
     <body>
        <?php
    	$dir = "http://site.server.com/images/";
    	
        $images = glob($dir . "*.png");
    
        foreach ($images as $image) 
    	{
        echo "<img src='$image' >";
        }
        ?>
    </body>
    </html>
    
     
  4. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,393
    First Name:
    Jim
    Sometimes when we use image editors they are saved with the file extension CAPITALIZED - so, also search for "*.PNG" images...
     
  5. ehymel

    ehymel

    Joined:
    Aug 12, 2007
    Messages:
    696
    glob will not work on remote servers. You will have to set $dir to be a local directory on your server to work.

    Alternatively, use JiminSA's script, changing the <a href> tags to <img> tags to get what you want.
     
  6. gurutech

    gurutech Thread Starter

    Joined:
    Apr 23, 2004
    Messages:
    2,960
    The $dir path is technically on the local server, just in the format of a full URL. I'll see how I can change that around to try it as a true "local" path - maybe just using "./folder" or /folder will work.
     
  7. JiminSA

    JiminSA

    Joined:
    Dec 15, 2011
    Messages:
    3,393
    First Name:
    Jim
    Yes it will work on localhost, as well as on your public domain, without modifications - you simply point your <img src= relative to your html pages location... e.g. if your html folder is way down deep in your website structure (for example htdocs/pages/html/ and the image folder is in a different directory then by starting your url path with ../ you direct the path starting from your base directory viz:- src="../graphics/site_images/fred.png". So by using ../ we direct the url relevant to the base directory.
    If we omit the ../ then the url path is relevant to your html's directory.
    Hope that helps...:)
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - display images folder
  1. FIRELISSA
    Replies:
    3
    Views:
    635
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1081872

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice