note 120693 added to function.scandir

From: Date: Wed, 22 Feb 2017 18:25:35 +0000
Subject: note 120693 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-208807@lists.php.net to get a copy of this message
BE AWARE! This omission cost me about 2 hours in debugging: It's worth noting that the PHP 4 example given does not include the closedir($dh) peice of it. I ran into a really frustrating bug where because I took it as "there is no need to close the directory," the rmdir() command (used after this custom scandir example) could not delete the empty directories I had created using PHP. In fact, when I tried to use the Linux command "ls -l" it told me "Permission Denied!" (because it was opened, but not closed). It should look like the example found on the http://au2.php.net/manual/en/function.opendir.php opendir() function reference page: $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); } } With the closedir($dh) or resource that was passed to it. ---- Server IP: 27.50.85.3 Probable Submitter: 96.90.163.237 ---- Manual Page -- http://php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/120693 Del: integrated -- https://master.php.net/note/delete/120693/integrated Del: useless -- https://master.php.net/note/delete/120693/useless Del: bad code -- https://master.php.net/note/delete/120693/bad+code Del: spam -- https://master.php.net/note/delete/120693/spam Del: non-english -- https://master.php.net/note/delete/120693/non-english Del: in docs -- https://master.php.net/note/delete/120693/in+docs Del: other reasons-- https://master.php.net/note/delete/120693 Reject -- https://master.php.net/note/reject/120693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208807) next »