Click to See Complete Forum and Search --> : php and is_dir()


Fandelem
03-27-2001, 02:47 PM
i'm wondering why it isn't recognizing directories from filenames.. i've tried both is_file() and is_dir()

has anyone gotten this working? here is my code:


// (this prints out files *and directories for some reason)
while($filename = readdir($dirhandle)) {
if ( !is_dir($filename) ) {
print("<option value=\"$filename\">$filename</option>");
}
}
}


and here is my first attempt that i thought would work (but doesn't)


while($filename = readdir($dirhandle)) {
if ( !is_dir($filename) ) {
if ( !is_file($filename) ) {
print("<option value=\"$filename\">$filename (directory)</option>");
}
else {
print("<option value=\"$filename\">$filename</option>");
}
}
}


any insight would be great :D :D

~kyle

EyesWideOpen
03-27-2001, 06:06 PM
You may want to read through the "User contributed notes" at the bottom of each of these pages from PHP.net (http://www.php.net):

is_file() (http://www.php.net/manual/en/function.is-file.php)
is_dir() (http://www.php.net/manual/en/function.is-dir.php)

It seems there have been some inconsistencies (sp?) in the way which these two functions have worked across different PHP versions and/or *NIX platforms.

[ 27 March 2001: Message edited by: EyesWideOpen ]

Fandelem
03-27-2001, 06:31 PM
i have read and tried every method -- yes, i have found inconsistencies and no user-contributed method worked for me -- i was just inquiring if anyone had gotten either to work *properly* ;o)

thanks,

~kyle

Sweede
03-28-2001, 01:25 AM
you need to open the directory handle before you read the directory..

$handle = opendir($directory);
while ($dir = readdir($handle) ) {
echo $dir;
}

Fandelem
03-28-2001, 02:02 AM
actually that's identical to what i have.. i just didn't put it in the snippet (sorry) hehe.. i guess it's filesystem dependant? hrrpmh hehe