getBytes() public method

This will load the file into memory. If the file is bigger than your memory, this will cause problems!
public getBytes ( ) : string
return string Returns a string of the bytes in the file
コード例 #1
0
ファイル: File.php プロジェクト: schpill/standalone
 /**
  * Get the bytes for this file.
  *
  * @return string|null
  */
 public function getBytes()
 {
     if ($this->isDirty && $this->bytes) {
         return $this->bytes;
     }
     if ($this->isDirty && $this->filename) {
         return file_get_contents($this->filename);
     }
     if ($this->mongoGridFSFile instanceof \MongoGridFSFile) {
         return $this->mongoGridFSFile->getBytes();
     }
     return null;
 }
コード例 #2
0
ファイル: EMongoGridFS.php プロジェクト: nmalservet/biocap
 /**
  * Returns the file's contents as a string of bytes
  * getBytes wrapper of MongoGridFSFile function
  * @return string string of bytes
  * False is returned if error
  * @since v1.3
  */
 public function getBytes()
 {
     Yii::trace('Trace: ' . __CLASS__ . '::' . __FUNCTION__ . '()', 'ext.MongoDb.EMongoGridFS');
     if (method_exists($this->_gridFSFile, 'getBytes') === true) {
         return $this->_gridFSFile->getBytes();
     } else {
         return false;
     }
 }
コード例 #3
0
ファイル: File.php プロジェクト: im286er/ent
 /**
  * 显示/下载资源信息
  *
  * @param MongoGridFSFile $gridFsFile            
  */
 public function output(\MongoGridFSFile $gridFsFile, $output = true, $download = false)
 {
     $fileInfo = $gridFsFile->file;
     $fileName = $fileInfo['filename'];
     if ($output) {
         setHeaderExpires();
         if (isset($fileInfo['mime'])) {
             header('Content-Type: ' . $fileInfo['mime'] . ';');
         }
         if ($download) {
             header('Content-Disposition:attachment;filename="' . $fileName . '"');
         } else {
             header('Content-Disposition:filename="' . $fileName . '"');
         }
         $stream = $gridFsFile->getResource();
         while (!feof($stream)) {
             echo fread($stream, 8192);
         }
     } else {
         return $gridFsFile->getBytes();
     }
 }
コード例 #4
0
ファイル: GridFS.php プロジェクト: saberyounis/Sonata-Project
 /**
  * @param \MongoGridFS $gridFs
  * @param \MongoGridFSFile $file
  */
 function it_should_rename_file($gridFs, $file)
 {
     $file->getBytes()->willReturn('some content');
     $file->getSize()->willReturn(12);
     $gridFs->findOne('otherFilename', array())->willReturn(null);
     $gridFs->findOne('filename', array())->shouldBeCalled()->willReturn($file);
     $gridFs->storeBytes('some content', array('date' => 1234, 'filename' => 'otherFilename'))->shouldBeCalled()->willReturn('someId');
     $fileToDelete = new \stdClass();
     $fileToDelete->file = array('_id' => 123);
     $gridFs->findOne('filename', array('_id'))->willReturn($fileToDelete);
     $gridFs->findOne(array('_id' => 'someId'))->willReturn($file);
     $gridFs->delete(123)->shouldBeCalled()->willReturn(true);
     $this->setMetadata('otherFilename', array('date' => 1234));
     $this->rename('filename', 'otherFilename')->shouldReturn(true);
 }
コード例 #5
0
ファイル: GridFSFile.php プロジェクト: sokil/php-mongo
 public function getBytes()
 {
     return $this->file->getBytes();
 }
コード例 #6
0
 public function testGetBytes()
 {
     $str = $this->object->getBytes();
     $this->assertEquals('abclmnorstxyz', $str);
 }