Solved

Displaying all images from a folder - how?

Posted on 2003-11-20
7
378 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
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WordPress Themes 10 34
What is the best PDF generator to use? 1 30
PHP: concatenate query 13 44
Testing a string condition in PHP 6 8
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

16 Experts available now in Live!

Get 1:1 Help Now