Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 /**
  * 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
  *
  * @return $this
  *
  * @throws RuntimeException If the filename does not point to a file that can be read.
  */
 public function setFileContentFromFilesystem($filename)
 {
     if (!$filename) {
         throw new RuntimeException('The filename may not be empty');
     }
     if (!is_readable($filename)) {
         throw new RuntimeException(sprintf('File "%s" not found or not readable', $filename));
     }
     $this->getContent();
     $stream = fopen($filename, 'rb');
     if (!$stream) {
         throw new RuntimeException(sprintf('Failed to open file "%s"', $filename));
     }
     $this->content->setData($stream);
     $this->content->setLastModified(new \DateTime('@' . filemtime($filename)));
     $finfo = new \finfo();
     $this->content->setMimeType($finfo->file($filename, FILEINFO_MIME_TYPE));
     $this->content->setEncoding($finfo->file($filename, FILEINFO_MIME_ENCODING));
     return $this;
 }