列出JSON目录中的所有图像

时间:2012-02-07 04:43:04

标签: php json

我需要以CLEAN json格式列出目录中的所有图像。我需要它看起来像这样:

URLLINK:"image of where the image is"

这就是我所需要的一切。

2 个答案:

答案 0 :(得分:11)

一行代码为:

echo json_encode(glob("*.{jpg,gif,png}", GLOB_BRACE));

参考文献:

答案 1 :(得分:8)

$files = array();

$dir = opendir('/tmp');
while ($file = readdir($dir)) {
    if ($file == '.' || $file == '..') {
        continue;
    }

    $files[] = $file;
}

header('Content-type: application/json');
echo json_encode($files);

像这样的东西。 您可以将其转换为您想要的任何结构