質問

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top