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.



Link to comment
Share on other sites

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 . '">';
}
Link to comment
Share on other sites

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
Link to comment
Share on other sites

[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 :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.