Log in

View Full Version : A little php help/suggestion



jzhang1013
08-28-2009, 04:58 AM
Hey so I have two folders:

- Thumbnails
- Actual Images

I want to write a php script that does the following...

<a href="fetch all actual images as a link"><img src="fetch all thumbnails to display"></a>

Here is my code to fetch all the thumbnails, but don't know how to do the link part...

<?php

$dirname = "./thumbnails";
$images = scandir($dirname);
$ignore = Array(".", "..", "error_log");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo "<li><img src='./thumbnails/$curimg' /></li>";
};
} *
?>


How would I go about doing this?

JShor
08-28-2009, 03:45 PM
This should work for you. If the images in the actualImages folder has the same file name as the ones in the thumbs, it's very simple.



<?php

$dirname = "./thumbnails";
$images = scandir($dirname);
$ignore = Array(".", "..", "error_log");
foreach($images as $curimg){
if(!in_array($curimg, $ignore)) {
echo '<li>
<a href="actualImages/'.$curimg.'"><img src="./thumbnails/'.$curimg.'" alt="" /></a></li>';
};
} *
?>


HTH:)

jzhang1013
08-29-2009, 03:21 AM
wow so simple, thanks man! but do you see any problems with this script and me using the lightbox script to open the photos?