Welcome Guest, Not a member yet? Register   Sign In
[Resolved] FTP - Recursive List Files and Folder
#1

[eluser]BrianLabs[/eluser]
Hello,
I got a small problem while trying to list files and folders from my FTP recursive.

The listing works but i don't get the right structure for the array.

Code:
public function list_files_rec($strPath = '/', $intLevel = 0) {
        $arrFolder = $this -> ftp -> list_files($strPath);
        
        foreach($arrFolder as $strFolder) {
            $arrList = $this -> ftp -> list_files($strFolder);
            
            foreach($arrList as $strItem) {
                $strSpace = str_repeat(' ', ($intLevel * 4));
                
                if(!stristr($strItem, '.')) {
                    //echo($strSpace . '<strong>Folder: ' . $strItem . '</strong><br />');
                    
                    $this -> arrResult[$strItem] = array();
                    
                    $this -> list_files_rec($strItem, ($intLevel + 1));
                } else {
                    //echo($strSpace . 'File: ' . $strItem . '<br />');
                    
                    $this -> arrResult[$strFolder][] = $strItem;
                }
            }
        }
    }

The Result looks like this http://pastebin.com/iBC7cjRH

Sometimes he put the things in the right way (e.g. /fb/classes/db/Crystal) together and sometimes not (e.g. /fb/classes/db/Crystal/Helper/)

What i want is a nested array of the file and folder structure that is exactly like on the server and files shouldn't be an array.

I mean
Code:
[/fb/contact.php] => Array
        (
            [0] => /fb/contact.php
        )

Should be
Code:
[0] => /fb/contact.php


Edit
Solved the problem a little bit.
Code:
/**
     * Permits you to retrieve a list of files on your server recursively.
     *
     * @access   public
     * @param    string   $strPath
     * @return   array
     */
    public function list_files_rec($strPath = '/') {
        static $arrResult = array();
        $arrFolder = $this -> ftp -> list_files($strPath);
        
        foreach($arrFolder as $strFolder) {
            if(strpos($strFolder, '.') === FALSE)
                $this -> list_files_rec($strFolder);
            
            $arrResult[$strPath][] = substr($strFolder, strlen($strPath) + 1);
        }
        
        return $arrResult;
    }

http://php.net/manual/en/function.ftp-nlist.php (first comment)

Now the result looks like this http://pastebin.com/My6sAAuT

But how can i get an array structure like i want it.
Code:
Array
(
    [/fb] => Array
        (
            [0] => contact.php
            [1] => famous.php
            [2] => index.php
            [3] => new.php
            [4] => privacy.php
            [5] => random.php
            [6] => speach.php
            [7] => classes
            [8] => includes
            [9] => layout
            [10] => files
            
            [/classes/tpl] => Array
                (
                    [0] => debug.tpl
                    [1] => Smarty.class.php
                    [2] => plugins
                    [3] => sysplugins
                    [/plugins] => Array()
                )
        )
)

I have no idea...




Theme © iAndrew 2016 - Forum software by © MyBB