# Solved: problem with php is_dir function



## andynic (May 25, 2007)

Hi,

Can someone explain why the php is_dir function seems to malfunction?

Please find below:
1. Output of a php script
2. The php script.
The herring bone <<<<< is meant to highlight the problem.
The code is also in the attachment if you want to try it on your system (change ".txt" to ".php").
The ".doc" file was made using MS Word 2003 on a Windows XP Prof. machine running in VMware Fusion and saved as type Webpage html.
The "..._files" directory contains images that were pasted into the html document.
php 5.3.8 running on Mac OS X 106.8

Output:
=====
../uploadimages/inkijkexemplaren/demoExemplaarAsHtmlBestand.doc is file
../uploadimages/inkijkexemplaren/demoExemplaarAsHtmlBestand_files is dir <<<<<<<<<<

. is dir
.. is dir
.DS_Store is file
demoExemplaarAsHtmlBestand.html is file
demoExemplaarAsHtmlBestand_files is file <<<<<<<<<<

php script:
========
<?php 
$file = "../uploadimages/inkijkexemplaren/demoExemplaarAsHtmlBestand.doc"; 
if ( is_dir($file) ) { echo "$file is dir
\n"; } else { echo "$file is file
\n"; }

$file = "../uploadimages/inkijkexemplaren/demoExemplaarAsHtmlBestand_files"; 
if ( is_dir($file) ) { echo "$file is dir
\n"; } else { echo "$file is file
\n"; }

echo "
\n";

$flHndl = opendir("../uploadimages/inkijkexemplaren");
$i=0;
while (($file = readdir($flHndl))) 
{
if ( is_dir($file) ) { echo "$file is dir
\n"; } else { echo "$file is file
\n"; }
} 
?>

Thanks for your help.
Andynic


----------



## andynic (May 25, 2007)

I found the problem: It's not the function, it's the script. Within the while loop, $file does not contain the path name.
This works: if ( is_dir ('../uploadimages/inkijkexemplaren/' . $file) ) .... 
Andynic


----------

