我已经编写了一个代码来获取所选文件夹以及所有子文件夹的大小,但我面临的问题是,无法在循环中增加大小计数器,
function getsize($username,$password,$server,$dir){
$connid = ftp_connect($server);
//ini_set('xdebug.max_nesting_level',500);
$connid = ftp_connect($server);
$login_result = ftp_login($connid, $username, $password);
$total_size = 0;
$contents_on_server = ftp_nlist($connid, $dir);
foreach($contents_on_server as $user_file) {
if(ftp_size($connid,$user_file) == -1){
$directory = $user_file;
$obj = new FTP();
$obj->getsize($username,$password,$server,$directory);
}
else{
//$file_size = ftp_size($connid,$user_file);
$total_size += ftp_size($connid,$user_file);
}
}
echo $total_size;
}"
如果我 print $total_size
,它输出为192944122391740
,所有三个文件的大小附加但不相加。
有什么帮助吗??