I'm trying to put a slideshow in Joomla, for this slideshow i want it to get all images for a folder, i use this code:
$dir = '/images/slideshow/breda';
$files = scandir($dir);
print_r($files);
echo '<div class="flexslider">';
echo '<ul class="slides">';
foreach($files as $file) {
echo '<li><img src="/images/slideshow/breda/';
echo $file;
echo '" alt="" title="" /></li>';
}
echo '</ul>';
echo '</div>';
print_r($file);
When i use print_r it does not give any data back.
What am i doing wrong?
You might want to consider using Joomla coding standards for this like so:
$path = JPATH_SITE . '/images/slideshow/breda/';
$files = JFolder::files($path);
print_r($files);
echo '<div class="flexslider">';
echo '<ul class="slides">';
foreach($files as $file) {
echo '<li><img src="/images/slideshow/breda/';
echo $file;
echo '" alt="" title="" /></li>';
}
echo '</ul>';
echo '</div>';
print_r($file);
I haven't tested what I've quickly mocked up, so please let me know if it works or not and I can update accordingly :)
Hope this helps
I used glob in my component which worked for me: http://php.net/manual/en/function.glob.php
An example of use:
$directory = 'images'.DS.'images'.DS;
$images = glob($directory . "{*.jpg,*.png,*.gif}",GLOB_BRACE);
foreach($images as $image){
Echo $image;
}
Always best to use Joomla coding standards if possible.
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.