Solved

Displaying all images from a folder - how?

Posted on 2003-11-20
7
381 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IP 10.0.1.2 / 255.0.0.0 61 56
How to make a good PHP + MySQL + JS pagination system? 3 34
ajax to record click 3 16
AJAX Wordpress Not Reading Variable 2 29
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…

828 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