?
Solved

Displaying all images from a folder - how?

Posted on 2003-11-20
7
Medium Priority
?
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 

Author Comment

by:wjdashwood
ID: 9786663
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
ID: 9786743
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
ID: 9786902
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:lozloz
ID: 9786925
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
ID: 9787244
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 2000 total points
ID: 9787355
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
ID: 9788203
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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

765 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