I'm new to PHP and having some troubles.
I need to get some images to display as:
<a rel="example_group" href="slidesstartpagina/DESOMVIELE-Bloemen-01.jpg" title="Desomviele bloemen en decoraties"><img src="slidesstartpagina/DESOMVIELE-Bloemen-01-tn.jpg" alt="" /></a>
The PHP code I wrote does display the first path perfectly for the <a href>
, but for the <img src>
it files with Array
instead of using the filename.
I must be doing something wrong using of that array.
Any Idea?
My code:
<?php
$paththumb = "img/bloemen_thumb/";
$pathimg = "img/bloemen_img/";
$images = preg_grep('/^([^.])/', scandir($pathimg));
$thumbs = preg_grep('/^([^.])/', scandir($paththumb));
$i=1;
foreach ($thumbs as $block) {
if ($i%16 == 1)
{
echo '<div class="block2 gallery">';
}
if ($thumbs[0] == '.');
foreach ($images as $value) {echo '<a rel="example_group" href="img/bloemen_img/'.$value.'" title="Desomviele bloemen en decoraties"><img src="img/bloemen_thumb/'.$thumbs.'" alt="" /></a>';
};
if ($i%4 == 0)
{
echo '</div>';
};
$i++;
if ($i%16 != 1) echo '</div>';
}
?>
You must put those div's inside "foreach" loop. If filenames are the same for thimbs and images you can use one loop:
Would be also great to check if file exists...