getBytes() публичный Метод

This will load the file into memory. If the file is bigger than your memory, this will cause problems!
public getBytes ( ) : string
Результат string Returns a string of the bytes in the file
Пример #1
0
 /**
  * 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
 /**
  * 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
 /**
  * 显示/下载资源信息
  *
  * @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
 /**
  * @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
 public function getBytes()
 {
     return $this->file->getBytes();
 }
 public function testGetBytes()
 {
     $str = $this->object->getBytes();
     $this->assertEquals('abclmnorstxyz', $str);
 }