Solved

Displaying all images from a folder - how?

Posted on 2003-11-20
7
380 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

786 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