note 102969 modified in function.ftp-nlist by thiago
| From: | thiago@php.net | Date: | Fri, 18 Mar 2011 19:48:58 +0000 |
| Subject: | note 102969 modified in function.ftp-nlist by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-177991@lists.php.net to get a copy of this message | ||
We needed to get a list of all files in all subdirectories and couldn't see a method to do this
so we wrote our own:
<?php
/**
* ftpRecursiveFileListing
*
* Get a recursive listing of all files in all subfolders given an ftp handle and path
*
* @param resource $ftpConnection the ftp connection handle
* @param string $path the folder/directory path
* @return array $allFiles the list of files in the format: directory => $filename
* @author Niklas Berglund
* @author Vijay Mahrra
*/
function ftpRecursiveFileListing($ftpConnection, $path) {
static $allFiles = array();
$contents = ftp_nlist($ftpConnection, $path);
foreach($contents as $currentFile) {
// assuming its a folder if there's no dot in the name
if (strpos($currentFile, '.') === false) {
ftpRecursiveFileListing($ftpConnection, $currentFile);
}
$allFiles[$path][] = substr($currentFile, strlen($path) + 1);
}
return $allFiles;
}
?>
--was--
We needed to get a list of all files in all subdirectories and couldn't see a method to do this
so we wrote our own:
/**
* ftpRecursiveFileListing
*
* Get a recursive listing of all files in all subfolders given an ftp handle and path
*
* @param resource $ftpConnection the ftp connection handle
* @param string $path the folder/directory path
* @return array $allFiles the list of files in the format: directory => $filename
* @author Niklas Berglund
* @author Vijay Mahrra
*/
function ftpRecursiveFileListing($ftpConnection, $path) {
static $allFiles = array();
$contents = ftp_nlist($ftpConnection, $path);
foreach($contents as $currentFile) {
// assuming its a folder if there's no dot in the name
if (strpos($currentFile, '.') === false) {
ftpRecursiveFileListing($ftpConnection, $currentFile);
}
$allFiles[$path][] = substr($currentFile, strlen($path) + 1);
}
return $allFiles;
}
http://php.net/manual/en/function.ftp-nlist.php