Page 1 of 1

God damn directory problems!!

Posted: Tue Jan 14, 2003 1:40 pm
by Gen-ik
I'm using the following script to view folders and files on my server.

It works because it's showing all the folders and files.. which is good.

The problem is that the is_file() and is_dir() calls aren't doing their job properly. Some times they work, some times they don't!

I've tried a range of CHMOD values on the files and folders but they seem to have no effect.

If you can help... HELP!

Code: Select all

<?php

if ($dir=opendir($path))
{
while (($file = readdir($dir)) !== false)
{
if(is_dir($file)==true) { echo($file." [folder]<br>\n"); }
elseif(is_file($file)==true) { echo($file." [file]<br>\n"); }
else { echo ($file." [don't have a clue!]<br>\n"); }
}  
closedir($dir);
}

?>

Posted: Tue Jan 14, 2003 2:04 pm
by volka
hmmm... may be a clearstatcache(); at the beginning of the script helps....

Posted: Tue Jan 14, 2003 5:07 pm
by Gen-ik
Nope.. clearstatcache(); doesn't seem to have any effect.

The script works fine showing the files and folders that it is in.. but when I try to go one step deeper into the directory it doesn't seem to like it.

For example, the script is in /test and it shows everything how I want it to, and tell me what's a folder and what's a file.

Now, if I try to read /test/extras the script will read and display everything ok but won't be able to tell what's a folder and what is a file!

Posted: Tue Jan 14, 2003 5:27 pm
by volka
readir($dir) will only return the name of the file, not the directory.
You have to prepend the directory name.
e.g. is_dir($dir.'/'.$file)

Posted: Tue Jan 14, 2003 6:06 pm
by Gen-ik
readir($dir) will only return the name of the file, not the directory.
You have to prepend the directory name.
e.g. is_dir($dir.'/'.$file)
Ah... got it working. Thank-you :D