Jump to content

Script to display all images in directory


skeetley

Recommended Posts

I am looking for a very simple script to auto retrieve the images from a dir and show them.  I don't care if the file needs to be placed in that dir or any other dir.  I don't care about formatting the output.  I just want a resulting page that I can go to and quickly scroll through my images.

I have checked the google and all I can find are scripts for actual image galleries.  I don't want to put that much work into this.  The ones that I thought should work, I couldn't get to work.

I used the search here.  The only similar question I found went unanswered.

Perhaps I am searching for the wrong terms.  Anyone know what I should search for?  Or know of such a script?

Many thanks.



Have a look here.  www.php.net/dir

use the dir function to return a list of files in the folder.

then once you have your list you can lloop through the list and write your image tags:

foreach($files as $file){
  echo '<img src="' . $file . '">';
}
Just wrote this real quick
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<?

foreach (glob("images/*.*") as $filename)
{
       print("<a href=\"$filename\">$filename<br><img src=\"$filename\"></a><hr>");
}

?>
</center>
</body>
</html>
[/code]

Regards,
John Sladek

can someone tell me how to put code in the post highliged as PHP.  I'm using the [ c o d e] tags
[quote author=jsladek link=topic=115024.msg468199#msg468199 date=1163557993]
Just wrote this real quick
[code]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<?

foreach (glob("images/*.*") as $filename)
{
      print("<a href=\"$filename\">$filename<br><img src=\"$filename\"></a><hr>");
}

?>
</center>
</body>
</html>
[/code]

Regards,
John Sladek

can someone tell me how to put code in the post highliged as PHP.  I'm using the [ c o d e] tags
[/quote]

Just use <?php  and ?> inside your [ co de] tags :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.