Insoftservice inso
asked on
php opendir not working
I want to scan for all folders and files within folder c:/data
But i am getting below error.
Warning: opendir(c:/data,c:/data): The system cannot find the file specified. (code: 2)
But i am getting below error.
Warning: opendir(c:/data,c:/data): The system cannot find the file specified. (code: 2)
function listFolderFiless($dir){
$ffs = scandir($dir);
$i = 0;
$list = array();
foreach ( $ffs as $ff ){
if ( $ff != '.' && $ff != '..' ){
if ( strlen($ff)>=5 ) {
if ( substr($ff, -4) == '.php' ) {
$list[] = $ff;
//echo dirname($ff) . $ff . "<br/>";
echo $dir.'/'.$ff.'<br/>';
}
}
if( is_dir($dir.'/'.$ff) )
$this->listFolderFiless($dir.'/'.$ff);
}
}
return $list;
}
But result is same
I think your path should be c:\data
ASKER
Tried even that
str_replace("/","\\","c:/d ata");
even tried giving hard code value.
This code worked on my local server but not on windows 2003 server
function ListIn($dir, $prefix = '') {
$dir = rtrim($dir, '\\/');
$result = array();
$h = opendir($dir);
while (($f = readdir($h)) !== false) {
if ($f !== '.' and $f !== '..') {
if (is_dir("$dir/$f")) {
$result = array_merge($result, $this->ListIn("$dir/$f", "$prefix$f/"));
} else {
$result[] = $prefix.$f;
}
}
}
closedir($h);
return $result;
}
str_replace("/","\\","c:/d
even tried giving hard code value.
This code worked on my local server but not on windows 2003 server
function ListIn($dir, $prefix = '') {
$dir = rtrim($dir, '\\/');
$result = array();
$h = opendir($dir);
while (($f = readdir($h)) !== false) {
if ($f !== '.' and $f !== '..') {
if (is_dir("$dir/$f")) {
$result = array_merge($result, $this->ListIn("$dir/$f", "$prefix$f/"));
} else {
$result[] = $prefix.$f;
}
}
}
closedir($h);
return $result;
}
This works fine for me.
$handle = opendir('C:\\Food')
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
windows 2003 server . php5.4
ASKER
Client had given permission to the folder on the server.
Its resolved thx
Its resolved thx