Directory browsing code???
Posted: Sat Oct 08, 2005 9:03 pm
Have the following function(s) which I borrowed from the PHP web site:
I am calling these functions and sometimes getting errorenous(sp) results...
Only it seems, when the directory passed to scan is that of the current working directory (either implicitly by scanning directory which currently executing script is in or by calling chdir() ) does the function return all results properly???
Anyone have alternative code which returns an array???
Please it's important these 2 functions stay as 2 and do not amalgamate - although technically the same results would be yielded...I need the functions kept as two
Anyone have any clue???
This code is driving me nutts
I'm running it on a shared host, running php 4.3.10 using Linux.
Thanks in advance
Code: Select all
function list_dirs($path_name='.')
{
$arr_dirs = array();
//
// Borrowed from the PHP web site
if($handle = opendir($path_name)){
while(false !== ($dir = readdir($handle))){
if(is_dir($dir)){
if($dir != '.' && $dir != '..')
$arr_dirs[] = $dir;
}
}
closedir($handle);
return $arr_dirs;
}
return false; // Error occurred :(
}
function list_files($path_name='.')
{
$arr_dirs = array();
//
// Borrowed from the PHP web site
if($handle = opendir($path_name)){
while(false !== ($dir = readdir($handle))){
if(is_file($dir)){
$arr_dirs[] = $dir;
}
}
closedir($handle);
return $arr_dirs;
}
return false; // Error occurred :(
}Only it seems, when the directory passed to scan is that of the current working directory (either implicitly by scanning directory which currently executing script is in or by calling chdir() ) does the function return all results properly???
Anyone have alternative code which returns an array???
Please it's important these 2 functions stay as 2 and do not amalgamate - although technically the same results would be yielded...I need the functions kept as two
Anyone have any clue???
This code is driving me nutts
I'm running it on a shared host, running php 4.3.10 using Linux.
Thanks in advance