size() public method

Files larger than 4GB will show up as being exactly 4GB.
public size ( string $filename ) : mixed
$filename string
return mixed
Example #1
0
 /**
  * @param string $identifier
  * @return array
  * @SuppressWarnings(PHPMD.Superglobals)
  */
 public function getDetails($identifier)
 {
     $details = [];
     $details['size'] = $this->sftp->size($identifier);
     $details['atime'] = $this->sftp->fileatime($identifier);
     $details['mtime'] = $this->sftp->filemtime($identifier);
     // ctime is not returned by phpseclinb so we just use mtime
     // because it will mostly be the same.
     // @see http://www.linux-faqs.info/general/difference-between-mtime-ctime-and-atime
     $details['ctime'] = $details['mtime'];
     $mimeType = false;
     if ($this->sftp->is_file($identifier)) {
         $fileExtMapping = $GLOBALS['TYPO3_CONF_VARS']['SYS']['FileInfo']['fileExtensionToMimeType'];
         $lcFileExtension = strtolower(substr($identifier, strrpos($identifier, '.') + 1));
         if (!empty($fileExtMapping[$lcFileExtension])) {
             $mimeType = $fileExtMapping[$lcFileExtension];
         }
     }
     if (false === $mimeType && isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][FileInfo::class]['mimeTypeGuessers']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][FileInfo::class]['mimeTypeGuesser'])) {
         $mimeTypeGuessers = $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][FileInfo::class]['mimeTypeGuesser'];
         foreach ($mimeTypeGuessers as $mimeTypeGuesser) {
             $hookParameters = ['mimeType' => &$mimeType];
             GeneralUtility::callUserFunction($mimeTypeGuesser, $hookParameters, $this);
         }
     }
     $details['mimetype'] = $mimeType;
     return $details;
 }
Example #2
0
 /**
  * Return file size.
  *
  * @param string $absolutePath The relative or absolute filename
  *
  * @return int
  *
  * @api
  */
 public function getFileSize(string $absolutePath) : int
 {
     return (int) $this->netSftp->size($absolutePath);
 }
Example #3
0
 /**
  * sync local directory with ftp directory
  *
  * @param string        $src
  * @param string        $dst
  * @param callable|null $syncop
  *
  * @throws GlSyncFtpException
  */
 public function syncDirectory($src, $dst, callable $syncop = null)
 {
     $this->login();
     $files = [];
     $dirs = [];
     $this->getFiles($dst, "", $files, $dirs);
     // delete on ftp server, files not present in local directory
     foreach ($files as $name => $raw) {
         if (!file_exists($src . $name)) {
             $filepathFtp = $dst . strtr($name, ["\\" => "/"]);
             if ($syncop) {
                 $syncop(self::DELETE_FILE, $filepathFtp);
             }
             $this->sftp->delete($filepathFtp);
         }
     }
     // delete on ftp server, unknowns directories
     $dirs = array_reverse($dirs);
     foreach ($dirs as $name => $raw) {
         if (!file_exists($src . $name)) {
             $filepathFtp = $dst . strtr($name, ["\\" => "/"]);
             if ($syncop) {
                 $syncop(self::DELETE_DIR, $filepathFtp);
             }
             $this->sftp->rmdir($filepathFtp);
         }
     }
     // create new directories
     $finderdir = new Finder();
     $finderdir->directories()->ignoreDotFiles(false)->followLinks()->in($src)->notName('.git*');
     /**
      * @var SplFileInfo $dir
      */
     foreach ($finderdir as $dir) {
         $dirpathFtp = $dst . "/" . strtr($dir->getRelativePathname(), ["\\" => "/"]);
         $stat = $this->sftp->stat($dirpathFtp);
         if (!$stat) {
             if ($syncop) {
                 $syncop(self::CREATE_DIR, $dirpathFtp);
             }
             $this->sftp->mkdir($dirpathFtp, $dir->getRealPath(), SFTP::SOURCE_LOCAL_FILE);
             $this->sftp->chmod(0755, $dirpathFtp, $dir->getRealPath());
         }
     }
     // copy new files or update if younger
     $finderdir = new Finder();
     $finderdir->files()->ignoreDotFiles(false)->followLinks()->in($src)->notName('.git*');
     /**
      * @var SplFileInfo $file
      */
     foreach ($finderdir as $file) {
         $filepathFtp = $dst . "/" . strtr($file->getRelativePathname(), ["\\" => "/"]);
         $stat = $this->sftp->stat($filepathFtp);
         if (!$stat) {
             if ($syncop) {
                 $syncop(self::NEW_FILE, $filepathFtp);
             }
             $this->sftp->put($filepathFtp, $file->getRealPath(), SFTP::SOURCE_LOCAL_FILE);
         } else {
             $size = $this->sftp->size($filepathFtp);
             if ($file->getMTime() > $stat['mtime'] || $file->getSize() != $size) {
                 if ($syncop) {
                     $syncop(self::UPDATE_FILE, $filepathFtp);
                 }
                 $this->sftp->put($filepathFtp, $file->getRealPath(), SFTP::SOURCE_LOCAL_FILE);
             }
         }
     }
 }