Log in

View Full Version : need syntax for $dir_handle = @opendir



bill.onthebeach
03-19-2010, 01:58 AM
Need a quick jumpstart,

I have this,

$dir_handle = @opendir($thumb_directory) or die . . .

but my files don't link with this

$thumb_directory = 'C:/Documents and Settings/. . . /thumb/';

where is the typo, I know it's simple, but this is my first attempt with php.

thanks in advance!

BLiZZaRD
03-19-2010, 02:22 AM
resource opendir ( string $path [, resource $context ] )

Opens up a directory handle to be used in subsequent closedir(), readdir(), and rewinddir() calls.




<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "filename: $file : filetype: " . filetype($dir . $file) . "\n";
}
closedir($dh);
}
}
?>


For example...

bill.onthebeach
03-19-2010, 02:28 AM
i have all that, and it works fine, i just didn't copy it to the thread.

the problem, unless I am wrong is in the setup:

$thumb_directory = 'C:/Documents and Settings/dontworryaboutit/ . . . /thumb/';

as I am getting an error message "cannot find files"

so I am thinking that there is a typo is the file path.

what say ye o wise one?

djr33
03-19-2010, 05:16 AM
You should be using a relative path, not an absolute path.

Just change that to '../dir/whatever/thumbs/" and it should work.

For more information, view the page on "readdir" at PHP.net because that shows several examples of the standard format.