note 110023 added to function.is-dir

From: Date: Wed, 12 Sep 2012 17:24:54 +0000
Subject: note 110023 added to function.is-dir
Groups: php.notes 
Request: Send a blank email to php-notes+get-190657@lists.php.net to get a copy of this message
I tried this code but i misplaced an "}" and the script displays files outside from my directory also and not able to understand why. Can anyone explain why Code with misplaced *}*: the misplaced *}* is on 8th line which needs to come after if(is_dir("$dir/$file")) { readall("$dir/$file"); } CODE::::: <?php function readall($dir) { if(file_exists($dir)) { $dr=opendir($dir) or die ('cannot open'); while($file=readdir($dr)) { if($file!='.' && $file!='..') { echo "$dir/$file" ."<br>"; } if(is_dir("$dir/$file")) { readall("$dir/$file"); } } closedir($dr); } } if (file_exists('.')) { readall('.'); } ?> Corrected code: <?php function readall($dir) { if(file_exists($dir)) { $dr=opendir($dir) or die ('cannot open'); while($file=readdir($dr)) { if($file!='.' && $file!='..') { echo "$dir/$file" ."<br>"; if(is_dir("$dir/$file")) { readall("$dir/$file"); } } } closedir($dr); } } if (file_exists('.')) { readall('.'); } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 117.220.181.227 ---- Manual Page -- http://www.php.net/manual/en/function.is-dir.php Edit -- https://master.php.net/note/edit/110023 Del: integrated -- https://master.php.net/note/delete/110023/integrated Del: useless -- https://master.php.net/note/delete/110023/useless Del: bad code -- https://master.php.net/note/delete/110023/bad+code Del: spam -- https://master.php.net/note/delete/110023/spam Del: non-english -- https://master.php.net/note/delete/110023/non-english Del: in docs -- https://master.php.net/note/delete/110023/in+docs Del: other reasons-- https://master.php.net/note/delete/110023 Reject -- https://master.php.net/note/reject/110023 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#190657) next »