Dynamically pulling images from a folder

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dynamically pulling images from a folder

kapral
Hi Guys.
This is my first attempt at using php code.
The page I'm creating has 26 galleries, each containing between 50-150 photographs so classic html code is getting extremely long. I started looking for a better solution and came across this php code, which seems to be exactly what I need.

My code looks like this:

<?php 
 if ($handle = opendir("../new/folder/")) { 
   while (false !== ($file = readdir($handle))) 
      { 
          if ($file != "." && $file != "..") 
          {$thelist.='<a href="../new/folder/"'.$file. 
		  'rel="shadowbox[new]" title="New"><img src="new.jpg">';} 
       } 
  closedir($handle); 
  } 
?> 
<?=$thelist?>

I'm getting repeated image links (the same image) for every image stored in the target folder. ie six images in the folder produces six image links all the same.
How can I make it a single link which when clicked opens the shadowbox?
Can enyone help the beginner please?
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically pulling images from a folder

rp1428
new.jpg is being shown for every image..



Reply | Threaded
Open this post in threaded view
|

Re: Dynamically pulling images from a folder

rp1428
In reply to this post by kapral
Sorry it removed part of my reply. Your img src statement is always specifying new.jpg
Reply | Threaded
Open this post in threaded view
|

Re: Dynamically pulling images from a folder

kapral
I named everything "new" to make it simplier.

The code can look like this:

<?php 
 if ($handle = opendir("../Beltring/")) { 
   while (false !== ($file = readdir($handle))) 
      { 
          if ($file != "." && $file != "..") 
          {$thelist.='<a href="../Beltring/"'.$file. 
		  'rel="shadowbox[beltring]" title="War and Peace Show"><img src="thumbnail.jpg">';} 
       } 
  closedir($handle); 
  } 
?> 
<?=$thelist?>