【问题标题】:Get images url from folder Filter only images from folder从文件夹中获取图像 url 仅过滤文件夹中的图像
【发布时间】:2014-02-01 12:32:40
【问题描述】:

我使用这里建议的代码 https://stackoverflow.com/a/18316453

这就是我现在所拥有的。

<?php
$dir = "sliders/slides";
$images = array();
if (is_dir($dir))
{
if ($dh = opendir($dir))
 {
  while (($file = readdir($dh)) !== false)
  {
    if (!is_dir($dir.$file)) $images[] = $dir . '/' . $file;
  }
  closedir($dh);
 } 
}
echo json_encode($images);
?>

我的结果包括 2 个额外的项目

sliders/slides/.
sliders/slides/..

这使我的滑块有 2 个额外的空白幻灯片

如何过滤结果以仅显示 .jpg 和 .png 文件,以便删除结果中包含的 /./..

我正在尝试创建从文件夹中获取图像的滑块

谢谢

【问题讨论】:

    标签: php jquery slider getfiles


    【解决方案1】:

    在while中尝试这样的事情:

    if ($file != "." && $file != ".." && !is_dir($file) {
        $images[] = $dir . '/' . $file;
    }
    

    【讨论】:

    • 太棒了!在我接受之前将等待一段时间。看来我暂时不能接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 1970-01-01
    相关资源
    最近更新 更多