note 110023 rejected from function.is-dir by danbrown
| From: | danbrown@php.net | Date: | Wed, 12 Sep 2012 17:25:53 +0000 |
| Subject: | note 110023 rejected from function.is-dir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190658@lists.php.net to get a copy of this message | ||
Note Submitter: manbirsingh at gmail dot com
----
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('.');
}
?>