display all images in a folder - help needed

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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?
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
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.
 

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>
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
Sometimes when we use image editors they are saved with the file extension CAPITALIZED - so, also search for "*.PNG" images...
 
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.
 

gurutech

Thread Starter
Joined
Apr 23, 2004
Messages
2,960
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.
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.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,407
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...:)
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

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 807,865 other people just like you!

Latest posts

Staff online

Members online

Top