Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display images with links in directory

Status
Not open for further replies.

kpdvx

Programmer
Dec 1, 2001
87
US
i want to take all images in a directory and display them with links to other pictures, a thumbnail gallery actually. in other words, the output should be multiple instances of this <a href=&quot;/full/image.jpg&quot;><img src=/thumb/image.jpg></a>

the images in the full directory and the thumb directory will have the same filename. any idea on how to do this?
 
Here's a little code snippet. It assumes that the thumbnails are in a subdirectory of your images directory called &quot;thumbs&quot; and that all your images end in jpg.

$dh = opendir (&quot;<path to images>&quot;);

while ($file = readdir ($dh))
{
if (preg_match (&quot;/jpg$/&quot;, $file))
{
$hfile = &quot;images/&quot;.$file;
$thumb = &quot;images/thumbs/&quot;.$file;
print &quot;<a href=\&quot;$hfile\&quot;><img src=\&quot;$thumb\&quot;></a>\n&quot;;
}
}

closedir ($dh);


______________________________________________________________________
Perfection in engineering does not happen when there is nothing more to add.
Rather it happens when there is nothing more to take away.
 
how could i make this display both gif's and jpg's? i tried using this: (preg_match (&quot;/jpg$ || gif$/&quot;, $file))

but this just displays everything in the directory.

thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top