note 70005 added to function.is-dir

From: Date: Fri, 29 Sep 2006 13:42:16 +0000
Subject: note 70005 added to function.is-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-117830@lists.php.net to get a copy of this message
The function is_dir will always return false if the handle acquired with opendir is not from the current working directory (getcwd); exception applies to "." and "..". Thus, if you need a consistent dir listing from any directory other than the current one, you must change dir first. Example follows: <?php chdir( '..' ); $rep=opendir('.'); while (false != ($file = readdir($rep))){ if (is_dir($file)){ print("<a href='$file/' class='text1'>$file</a>"); } } ?> The above code will list all directories (with links) for the ".." directory, relative to the current working dir. THE WRONG WAY TO DO IT FOLLOWS: <?php $rep=opendir('..'); while (false != ($file = readdir($rep))){ //print "$file is here (may be a dir or not)<br>"; if (is_dir($file)){ print "<a href='$file/' class='text1'>$file</a><br>"; } } ?> This code will turn into an empty list. If you want to make sure, uncomment the commented line... Regards... ---- Server IP: 200.185.126.100 Probable Submitter: 200.222.25.112 (proxied: 1.0 SPRLG01) ---- Manual Page -- http://www.php.net/manual/en/function.is-dir.php Edit -- https://master.php.net/note/edit/70005 Del: integrated -- https://master.php.net/note/delete/70005/integrated Del: useless -- https://master.php.net/note/delete/70005/useless Del: bad code -- https://master.php.net/note/delete/70005/bad+code Del: spam -- https://master.php.net/note/delete/70005/spam Del: non-english -- https://master.php.net/note/delete/70005/non-english Del: in docs -- https://master.php.net/note/delete/70005/in+docs Del: other reasons-- https://master.php.net/note/delete/70005 Reject -- https://master.php.net/note/reject/70005 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117830) next »