Identifying files from directories


The code below seems to work when I specify the root directory:

$dir = opendir("./");

But when I specify a sub-directory,

$dir = opendir("original_files");

the filename (named $file in the code) returns false for both is_file and is_dir regardless whether it is actually a file or a directory. Can anyone point me out where I am going wrong?

		$dir = opendir("original_files");

		echo '<ul>';
		while ($file = readdir($dir)) {
			echo '<li>'.$file.'</li>';
			echo 'File: ';
			echo 'Directory: ';
		echo '</ul>';



Thanks heaps,

What exactly are you trying to do? Get a directory listing? A file listing?

Incidently, ‘./’ is not the root directory. It is the current directory - the directory the initial PHP script started in. The root directory is ‘/’

Hey thanks for the quick reply.

I would like to list the contents within a directory, and be able to identify between a file and directory. i.e. I could wrap the directory filenames with an anchor tag so you could click through and have the folders open to show the contents within those.

Use the [fphp]glob[/fphp] function then. It’s quicker, easier and more powerful than the approach you’re taking. Read its manual entry, and if you have any questions post them here and I or someone else will answer.

Thanks for your help Michael will do.