示例#1
0
文件: File.php 项目: vespolina/media
 /**
  * Set the content for this file from the given filename.
  * Calls file_get_contents with the given filename
  *
  * @param string $filename name of the file which contents should be used
  */
 public function setFileContentFromFilesystem($filename)
 {
     $this->getContent();
     $stream = fopen($filename, 'rb');
     if (!$stream) {
         throw new \RuntimeException("File '{$filename}' not found");
     }
     $this->content->setData($stream);
     $this->content->setLastModified(new \DateTime('@' . filemtime($filename)));
     $finfo = new \finfo();
     $this->content->setEncoding($finfo->file($filename, FILEINFO_MIME_ENCODING));
     $this->content->setMimeType($finfo->file($filename, FILEINFO_MIME_TYPE));
     $this->updateDimensionsFromContent();
 }
示例#2
0
 /**
  * Set the content for this file from the given resource or string.
  *
  * @param resource|string $content the content for the file
  *
  * @return $this
  */
 public function setFileContent($content)
 {
     $this->getContent();
     if (!is_resource($content)) {
         $stream = fopen('php://memory', 'rwb+');
         fwrite($stream, $content);
         rewind($stream);
     } else {
         $stream = $content;
     }
     $this->content->setData($stream);
     return $this;
 }