Hello,
I've got a problem with opendir($dir) function. When I use opendir(".") everything is OK but when I call opendir($dir), program works strange - is_dir() and is_file() return wrong results then.
For example (both scripts are written bellow):
I have a directory "test1" with "Script1.php" and directory "test1/test2" with "Script2.php".
Both scripts are equal except for opendir parameter.
Script2.php (using opendir(".")) works just fine.
Script1.php (using opendir("test2") and writing out the content of the same (test2) directory as Script1.php) works incorrectly - it can't say, if $file is a directory or a file (is_dir and is_file both returns false).
Please, help me to fix it. How to tell the exact path to an opendir() function since "dir", "dir/", 'dir', 'dir/' doesn't work and the only parameters that works fine for me are "." or ".." (and '.', './' and so on...).
I'm feeling quite helpless.
I'd be grateful for any advice.
Radek
======Script1.php in test1 directory=================
$handle=opendir("test2");
//not ".", it's the only difference between the two scripts
while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if (is_dir($file))
echo "Dir $file <br>\n";
elseif (is_file($file))
echo "File $file <br>\n";
}
}
closedir($handle);
====Script2.php in test2 directory=================
$handle=opendir(".");
while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if (is_dir($file))
echo "Dir $file <br>\n";
elseif (is_file($file))
echo "File $file <br>\n";
}
}
closedir($handle);
==================================================
I've got a problem with opendir($dir) function. When I use opendir(".") everything is OK but when I call opendir($dir), program works strange - is_dir() and is_file() return wrong results then.
For example (both scripts are written bellow):
I have a directory "test1" with "Script1.php" and directory "test1/test2" with "Script2.php".
Both scripts are equal except for opendir parameter.
Script2.php (using opendir(".")) works just fine.
Script1.php (using opendir("test2") and writing out the content of the same (test2) directory as Script1.php) works incorrectly - it can't say, if $file is a directory or a file (is_dir and is_file both returns false).
Please, help me to fix it. How to tell the exact path to an opendir() function since "dir", "dir/", 'dir', 'dir/' doesn't work and the only parameters that works fine for me are "." or ".." (and '.', './' and so on...).
I'm feeling quite helpless.
I'd be grateful for any advice.
Radek
======Script1.php in test1 directory=================
$handle=opendir("test2");
//not ".", it's the only difference between the two scripts
while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if (is_dir($file))
echo "Dir $file <br>\n";
elseif (is_file($file))
echo "File $file <br>\n";
}
}
closedir($handle);
====Script2.php in test2 directory=================
$handle=opendir(".");
while (false!==($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
if (is_dir($file))
echo "Dir $file <br>\n";
elseif (is_file($file))
echo "File $file <br>\n";
}
}
closedir($handle);
==================================================