Solved

Displaying all images from a folder - how?

Posted on 2003-11-20
7
377 Views
Last Modified: 2006-11-17
I'm going to have a folder containing images hosted on the internet. What I would like is the ability to display a thumbnail of all the images in the folder (or a message if there are none, but i can do that bit) when the path to the image folder is provided. It going to have to be some kind of loop but I have no idea how to do this. Is it going to be a repeat until EOF? I have not really worked with folders and files in this way before. Can anyone provide some light on the matter for me?

Thanks
H

www.d6online.co.uk
0
Comment
Question by:wjdashwood
  • 4
  • 3
7 Comments
 

Author Comment

by:wjdashwood
Comment Utility
Oh i forgot to mention that these thumbnails have to be able to be selected, and therefore must be able to be identified singulary. if that makes sense.
0
 
LVL 13

Expert Comment

by:lozloz
Comment Utility
it's quite simple really:

<?
// Thumbnail generator

$thumbdir = "images/thumbnails"; // folder to contain thumbnails
if($dir = opendir($thumbdir)){
  for($x = 0; $file = readdir($dir); $x++) {
    $shorten = strtolower(substr($file, -3));
    if($shorten == "jpg" || $shorten == "gif" || $shorten == "png") {
      print "<img src=\"$thumbdir . "/" . $file\" alt=\"$file\" height=\"$height\" width=\"$xsize=\" border=\"0\"><br /><br />\n";
    }
  }
  if($x == 0) {
    print "No images found";
  }
} else {
  print "Unable to open directory";
}
?>

this can be expanded a lot to provide links to full size images, include captions based on filenames, resize thumbnails using gd image functions etc. so have a play around really

loz
0
 

Author Comment

by:wjdashwood
Comment Utility
That looks like what I was wanting, thanks
The only question i have still is if I put a button under each image how would that be able to be associated with it? I want the button to be able to be pressed and the image file name to be able to be sent. Any ideas?

Thanks
H
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:lozloz
Comment Utility
what sort of button do you want? a form button or just an image? what do you want the image to do - open the thumbnail again in a new window, open a different image or maybe open a fullsize image of the same filename from a different folder?

loz
0
 

Author Comment

by:wjdashwood
Comment Utility
i want the button (any button really i can change that later) to insert the image into a rich text box, so to pass the filename to the other page is enough.
0
 
LVL 13

Accepted Solution

by:
lozloz earned 500 total points
Comment Utility
i don't know what you mean by a rich text box.. but here's how to pass the filename (without directory info) to another page using a link

<?
// Thumbnail generator

$thumbdir = "images/thumbnails"; // folder to contain thumbnails
if($dir = opendir($thumbdir)){
  for($x = 0; $file = readdir($dir); $x++) {
    $shorten = strtolower(substr($file, -3));
    if($shorten == "jpg" || $shorten == "gif" || $shorten == "png") {
      print "<img src=\"$thumbdir . "/" . $file\" alt=\"$file\" height=\"$height\" width=\"$xsize=\" border=\"0\"><br /><br /><a href=\"yourpage.php?filename=$file\" target=\"_blank\">Send filename</a>" . \n";
    }
  }
  if($x == 0) {
    print "No images found";
  }
} else {
  print "Unable to open directory";
}
?>

you'll need to change yourpage.php. the variable can then be access from that page using $_GET["filename"]

loz
0
 

Author Comment

by:wjdashwood
Comment Utility
The passing to the rich text box is done elsewhere anyway, that is what I was wanting, just the link to pass the filename.

Thank you very much
Hayley
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now