Is_dir does not recognize directories. What for?

I have this function:

if (is_dir($dir)) { //are we able to open it? if ($dh = opendir($dir)) { //Let cycle while (($subdir = readdir($dh)) !== false) { if ($subdir != "." && $subdir != "..") { echo $subdir; } } } 

This returns:

 directory1 , directory2, directory3 etc.. etc.. 

If I do this:

  if (is_dir($dir)) { //are we able to open it? if ($dh = opendir($dir)) { //Let cycle while (($subdir = readdir($dh)) !== false) { if ($subdir != "." && $subdir != "..") { if (is_dir($subdir)) { echo $subdir; } } } } 

He doesn't print anything!

Why is this happening? I am running a script with windows and XAMPP for testing. A directory does contain directories.

thanks

+4
source share
3 answers

is_dir($dir . '/' . $subdir)

+11
source

readdir () indicates only the file name / dir, not the full path (which is apparently is_dir).

Found here - http://www.php.net/manual/en/function.is-dir.php#79622

+4
source

Because $dir is the full path, where $subdir is just a fragment of the path

+1
source

Source: https://habr.com/ru/post/1307332/


All Articles