mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-28 12:10:59 +00:00
SFTP: add optional $recursive parameter to filesize()
This commit is contained in:
parent
f418be845b
commit
b8f8f0b7db
@ -2829,15 +2829,37 @@ class SFTP extends SSH2
|
|||||||
return $this->get_stat_cache_prop($path, 'gid');
|
return $this->get_stat_cache_prop($path, 'gid');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively go through rawlist() output to get the total filesize
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private static function recursiveFilesize(array $files)
|
||||||
|
{
|
||||||
|
$size = 0;
|
||||||
|
foreach ($files as $name => $file) {
|
||||||
|
if ($name == '.' || $name == '..') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$size+= is_array($file) ?
|
||||||
|
self::recursiveFilesize($file) :
|
||||||
|
$file->size;
|
||||||
|
}
|
||||||
|
return $size;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets file size
|
* Gets file size
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
* @param bool $recursive
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function filesize($path)
|
public function filesize($path, $recursive = false)
|
||||||
{
|
{
|
||||||
return $this->get_stat_cache_prop($path, 'size');
|
return !$recursive || $this->filetype($path) != 'dir' ?
|
||||||
|
$this->get_stat_cache_prop($path, 'size') :
|
||||||
|
$this->recursiveFilesize($this->rawlist($path, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user