Gaufrette\File::getSize PHP Method

getSize() public method

public getSize ( ) : integer
return integer size of the file
    public function getSize()
    {
        if ($this->size) {
            return $this->size;
        }
        try {
            return $this->size = $this->filesystem->size($this->getKey());
        } catch (FileNotFound $exception) {
        }
        return 0;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Returns the size of the file
  *
  * !! WARNING !!
  * Calling this loads the entire file into memory,
  * unless it is on a stream-capable filesystem.
  * In case of bigger files this could throw exceptions,
  * and will have heavy performance footprint.
  * !! ------- !!
  *
  */
 public function getSize()
 {
     // This can only work on streamable files, so basically local files,
     // still only perform it once even on local files to avoid bothering the filesystem.php g
     if ($this->filesystem->getAdapter() instanceof StreamFactory && !$this->size) {
         if ($this->streamWrapperPrefix) {
             try {
                 $this->setSize(filesize($this->streamWrapperPrefix . $this->getKey()));
             } catch (\Exception $e) {
                 // Fail gracefully if there was a problem with opening the file and
                 // let gaufrette load the file into memory allowing it to throw exceptions
                 // if that doesn't work either.
                 // Not empty to make the scrutiziner happy.
                 return parent::getSize();
             }
         }
     }
     return parent::getSize();
 }
All Usage Examples Of Gaufrette\File::getSize