Reputation: 183
I have a peice of code that I was using for an old website and want to use it again in my new site, but the images aren't showing up for some reason.
The path to my gallery is correct and the code is a copy of an old working script. Can anyone suggest why this isn't working?
<?php
$folder = 'http://localhost/website/magazine/photos/galleries/2016/gallery/';
$filetype = '*.*';
$files = glob($folder.$filetype);
foreach ($files as $file)
{
echo '
<div class=\"galleryCell\">
<a class="fancybox" rel="group" href="'.$file.'">
<img class=\"galleryThumb\" src="'.$file.'" />
<div class=\"galleryThumbCover\"></div>
</a>
</div>
';
}
?>
Upvotes: 1
Views: 477
Reputation: 4925
You can't use direct URL's for the glob()
function. It needs the path of server folder e.g. magazine/photos/galleries/2016/gallery/
. So your script would be something like this:
<?php
$folder = 'magazine/photos/galleries/2016/gallery/';
$filetype = '*.{jpg,jpeg,png,gif}*';
$files = glob($folder.$filetype, GLOB_BRACE); # GLOB_BRACE for the multiple extensions (Using brackets)
foreach ($files as $file)
{
echo '
<div class="galleryCell">
<a class="fancybox" rel="group" href="'.$file.'">
<img class="galleryThumb" src="'.$file.'" />
<div class="galleryThumbCover"></div>
</a>
</div>
';
}
?>
Don't forget to change the path if I put the wrong path.
See reference: Glob not giving me any results
I hope this will work for you
Upvotes: 1
Reputation: 894
Try this it will be helpfull for you
<?php
$folder = '/magazine/photos/galleries/2016/gallery/';
$filetype = '*.{jpg,jpeg,png,gif}*';
$files = glob($folder.$filetype,GLOB_BRACE);
foreach ($files as $file)
{
echo '
<div class=\"galleryCell\">
<a class="fancybox" rel="group" href="'.$file.'">
<img class=\"galleryThumb\" src="'.$file.'" />
<div class=\"galleryThumbCover\"></div>
</a>
</div>
';
}
?>
Upvotes: 0