is_dir 无法识别目录。为什么?
我有这个函数:
if (is_dir($dir)) {
//are we able to open it?
if ($dh = opendir($dir)) {
//Let's cycle
while (($subdir = readdir($dh)) !== false) {
if ($subdir != "." && $subdir != "..") {
echo $subdir;
}
}
}
这返回:
directory1 , directory2, directory3 etc.. etc..
然而,如果我这样做:
if (is_dir($dir)) {
//are we able to open it?
if ($dh = opendir($dir)) {
//Let's cycle
while (($subdir = readdir($dh)) !== false) {
if ($subdir != "." && $subdir != "..") {
if (is_dir($subdir)) {
echo $subdir;
}
}
}
}
它不会打印任何内容!
为什么会出现这种情况? 我正在使用 Windows 和 XAMPP 运行脚本以进行测试。该目录实际上包含目录。
谢谢
I have this function:
if (is_dir($dir)) {
//are we able to open it?
if ($dh = opendir($dir)) {
//Let's cycle
while (($subdir = readdir($dh)) !== false) {
if ($subdir != "." && $subdir != "..") {
echo $subdir;
}
}
}
This returns:
directory1 , directory2, directory3 etc.. etc..
Hoever if I do this:
if (is_dir($dir)) {
//are we able to open it?
if ($dh = opendir($dir)) {
//Let's cycle
while (($subdir = readdir($dh)) !== false) {
if ($subdir != "." && $subdir != "..") {
if (is_dir($subdir)) {
echo $subdir;
}
}
}
}
It doesn't print nothing!
Why does this happens?
I'm running the script withing windows and XAMPP for testing purposes. The directory does in fact contain directories.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
is_dir($dir . '/' . $subdir)
is_dir($dir . '/' . $subdir)
readdir() 只给出文件/目录名称,而不给出完整路径(显然 is_dir 需要)。
在这里找到 - http://www.php.net/manual /en/function.is-dir.php#79622
readdir() only gives the file/dir name and not the full path (which is_dir apparently needs).
Found here - http://www.php.net/manual/en/function.is-dir.php#79622
这是因为
$dir
是完整路径,而$subdir
只是路径片段Its because
$dir
is a full path where as$subdir
is only a path fragment