[eluser]Dave Blencowe[/eluser]
Hi there,
Recently I have been attempting to extend the CI FTP class so that I can issue a command and it will recursively list files/folders in a multi-dimensional array. I have provided an example below:
array (
index.php
style.css
application/
views/
welcome.php
controllers/
welcome.php
system/
files.php
);
So far I have developed the following code which does the first level of the supplied dir but I need to make it recursive
Code:
<?php
class MY_FTP extends CI_FTP {
function map ($path, $depth = 5)
{
if ( ! $this->_is_conn())
{
return FALSE;
}
ftp_chdir($this->conn_id, $path);
$pwd = ftp_pwd($this->conn_id);
${$pwd} = array();
$cur = $this->list_files($path);
$base = $pwd;
$i = 0;
$filter = array('.', '..', 'cgi-bin');
foreach($cur as $item) {
$res = ftp_size($this->conn_id, $item);
${$pwd}[$item]['name'] = $item;
if("$res" != "-1") {
${$pwd}[$item]['type'] = 'file';
} else {
${$pwd}[$item]['type'] = 'dir';
}
if (in_array(${$pwd}[$item]['name'], $filter))
{
unset(${$pwd}[$item]);
}
$i++;
}
foreach (${$pwd} as $item) {
if ($item['type'] == 'dir')
{
${$pwd}[$item['name']]['sub'] = $this->list_files($path."/".$item['name']);
}
}
return ${$pwd};
}
}
Any ideas would be welcome?
Thanks a lot for any help that may be offered,
Dave