0

我想在组合框中的文件夹中获取文件名。这是我的代码

$directory = "keys/";

//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");
 echo "yes";
//print each file name
foreach($images as $image)
{
echo $image;
}

它应该显示文件名,但没有显示任何文件名。

4

1 回答 1

1

尝试运行它应该可以帮助您调试代码。您应该在将来进行调试。

/*
 * glob() a pattern inside a directory
 */
$directory = "keys/";
$pattern   = "*.jpg";

if (!is_dir($directory)) {
    throw new Exception('Directory was not found!');
}

$images = glob($directory . $pattern);

if (FALSE === $images) {
    throw new Exception('Glob returned an error.');
}

if (!$images) {
    throw new Exception('No files returned by Glob. That was not expected.');
}

// print each file name
foreach ($images as $image) {
    echo $image;
}
于 2012-12-31T16:37:25.107 回答