opendir用于打开目录,而不是文件:-)
您还可以尝试暂时调试调试内容,以便了解正在发生的事情:
function IsNotEmpty ($folder) {
$files = array ();
if ($handle = opendir ($folder)) {
echo "DEBUG opened okay ";
while (false !== ($file = readdir ($handle))) {
if ( $file != "." && $file != ".." ) {
$files [] = $file;
echo "DEBUG got a file ";
}
}
closedir ($handle);
} else {
echo "DEBUG cannot open ";
}
return (count($files) > 0 ) ? TRUE : FALSE;
}
$dir ="/Site/images/countries/abc/a";
if (IsNotEmpty($dir)) {
echo "There is no such file";
} else {
echo "The file exists!";
}如果仍然无法正常工作,并且您确定该目录存在(请记住,案例对UNIX很重要),您可能需要查看该目录的权限,以确保允许尝试访问该目录的用户ID。