note 50009 added to function.readdir

From: Date: Tue, 15 Feb 2005 09:12:03 +0000
Subject: note 50009 added to function.readdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-85059@lists.php.net to get a copy of this message
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. ---- Manual Page -- http://www.php.net/manual/en/function.readdir.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50009 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50009&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50009&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50009&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50009&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50009&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50009&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85059) next »