Craig
Craig

Reputation: 397

How to get path of file returned by PHP ftp_rawlist()

I got this PHP function which returns an array of all files using PHP's ftp_rawlist() and it is working well for me...

However, I currently have no way of knowing the path the returned filename is located in on the FTP server. Does anyone have any ideas on how I can also get the path to the file location on the FTP server along with the name of the file ?

   function listDetailed($resource, $directory) { 
    if (is_array($children = @ftp_rawlist($resource, $directory,true))) { 
        $items = array(); 

        foreach ($children as $child) { 
            $chunks = preg_split("/\s+/", $child); 
            @list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'],$item['month'], $item['day'], $item['time'], $item['filename']) = $chunks; 
            @$item['type'] = $chunks[0]{0} === 'd' ? 'directory' : 'file'; 
            @array_splice($chunks, 0, 8); 
            @$items[implode(" ", $chunks)] = $item; 
        } 

        return $items; 
    } 

    // Throw exception or return false < up to you 
} 

Upvotes: 1

Views: 1185

Answers (1)

Root
Root

Reputation: 2349

You just need to add $directory path to start of a filename .
for example :

/*... some codes                               This exactly     */ 
@list($item['time'], $item['filename'], $directory.'/'.$item['filename']) = $chunks;

Upvotes: 1

Related Questions