How to Get File Size of Files on FTP Server?

2019-09-06 14:41发布

I need a list of all the files (and associated file sizes) on an FTP server. I can get a list of files using CodeIgniter’s FTP class, but no idea how to get the file size. How do I get the file sizes? Thanks.

7条回答
beautiful°
2楼-- · 2019-09-06 15:22

Just had a quick look at CodeIgniters FTP class.. As its written with backwards compat for PHP4 you could probabaly do this (hack job) if you must.

<?php
$files = $this->ftp->list_files('/folder/');

foreach ($files as $file)
{
  echo 'File:'. $file .' Size: '. ftp_size($this->ftp->conn_id, $file) .' <br />';
}
$this->ftp->close();

I wouldn't recommend this - It's probabably worth extending the main CI ftp class

class FTP extends CI_FTP
{

  function FTP()
  {
    // call parent constructor
    parent::CI_FTP();
  }

  // Single file size
  function file_size($file)
  {
    return ftp_size($this->conn_id, $file);
  }
}

Put the above into your application/libraries and save it as ftp.php. If you're running an updated version of CI it'll load your extension.

查看更多
登录 后发表回答