[英]Scandir does not work in Joomla
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: 我正在尝试在Joomla中放一个幻灯片,为此幻灯片我希望它获取文件夹的所有图像,我使用以下代码:
$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. 当我使用print_r时,它不返回任何数据。
What am i doing wrong? 我究竟做错了什么?
You might want to consider using Joomla coding standards for this like so: 您可能需要考虑使用Joomla编码标准,例如:
$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 我在对我有用的组件中使用了glob: 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. 如果可能,始终最好使用Joomla编码标准。
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.