/** * 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; }
/** * 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; } }
/** * 显示/下载资源信息 * * @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(); } }
/** * @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); }
public function getBytes() { return $this->file->getBytes(); }
public function testGetBytes() { $str = $this->object->getBytes(); $this->assertEquals('abclmnorstxyz', $str); }