note 50009 deleted from function.readdir by tularis

From: Date: Sun, 13 May 2007 19:03:46 +0000
Subject: note 50009 deleted from function.readdir by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-126531@lists.php.net to get a copy of this message
Note Submitter: steve at stevedix dot de ---- IT IS VITALLY IMPORTANT that when using opendir and then scanning with readdir, that you test opendir to see if it has returned a valid pointer. The following code does not : <?php $dir = opendir($mydir); while((false!==($file=readdir($dir)))) if($file!="." and $file !="..") unlink($mydir.'/'.$file); closedir($dir); ?> if $mydir is not a valid directory resource (for example, the directory in question has been deleted), then the code will loop infinitely. Of course, it'll stop eventually if you have set a max execution time, but in the meantime it will visibly slow the server.

« previous php.notes (#126531) next »