You are here: Directory Recursion and Multidimensional Arrays « PHP Programming Language « IT news, forums, messages
Directory Recursion and Multidimensional Arrays

Posted by Tyrone Slothrop on 09/25/06 18:24

I have created a script which recurses a display of directories like
so:

<?
$dir = "/path/to/base/directory";
function scan_dir_recurse ($dir,$tab)
{
global $fileArr;
$tab++;
if ($tab > 4) { exit ("Tab length exceeded."); }
$files = scandir($dir);
for ($i=0; $i<count($files); $i++)
{
if ($files[$i] != '.' && $files[$i] != '..')
{
echo str_repeat(" ", $tab-1).$files[$i]."\n";
if (is_dir($dir.'/'.$files[$i]))
{
scan_dir_recurse ($dir.'/'.$files[$i],$tab);
}
}
}
}
scan_dir_recurse($dir,0);
?>

What is want to do is generate a multidimensional array which will be
accessable on a DHTML page of select boxes where, a user first selects
a top directory, then a select box appears of directories under it,
etc. until a list of available files is available.

For example:
$fileArr[0] = 'dir1';
$fileArr[0][0] = 'dir2';
$fileArr[0][0][0] = 'dir3';
$fileArr[0][0][0][0] = 'a_file';

The solution to adding another level of recursion to the array escapes
me at the moment. Any ideas?

TIA!

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация