In article <y3*****************@newssvr22.news.prodigy.com> , Michael Austin wrote:
Oliver Otto wrote:
Pedro Graca wrote:
Oliver wrote:
Hi,
I wrote earlier this day about this problem but thought it had
something to do with images. However, I found out that for some reason
the readdir function is not working properly on my Suse 9.1 server. I
can only read a random number of files and directories per folder.
When I repeat the command for the same folder I get the same output.
So it is not random.
It is random for each directory, but there it is same as lang as I don't
change or add a file/folder.
If I use the readdir test script on an older machine everything works
fine.
What is the loop inside which is the readdir() call?
Specifically the test condition?
Thats my readdir test script:
<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('./')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}
?>
Oliver
Looks like you are missing the @opendir
if ($handle = @opendir('./'))
The @ will only hide errors. So in this case i would certainly not
recommend to use it. Below is the function i use to obtain the files in
a directory. It can be easily expanded to support recursion too.
function listdir($directory) {
$results = array();
if ($handler = @opendir($directory)) {
while ($file = readdir($handler)) {
if (!is_dir($directory.'/'.$file)) {
$results[] = $file;
}
}
closedir($handler);
}
return $results;
}
--
Tim Van Wassenhove <http://home.mysth.be/~timvw>