예제 #1
0
파일: Image.php 프로젝트: bazo/Tatami
 /**
  * Get format from the image stream in the string.
  * @param  string
  * @return mixed  detected image format
  */
 public static function getFormatFromString($s)
 {
     $types = array('image/jpeg' => self::JPEG, 'image/gif' => self::GIF, 'image/png' => self::PNG);
     $type = Utils\MimeTypeDetector::fromString($s);
     return isset($types[$type]) ? $types[$type] : NULL;
 }
예제 #2
0
 /**
  * @param $file
  * @param $content
  * @param $contentType
  * @param $disposition
  * @return array
  * @throws FileNotFoundException
  */
 private function createAttachment($file, $content, $contentType, $disposition)
 {
     if ($content === NULL) {
         $content = @file_get_contents($file);
         if ($content === FALSE) {
             throw new FileNotFoundException("Unable to read file '{$file}'.");
         }
     } else {
         $content = (string) $content;
     }
     $attachment = array('type' => $contentType ? $contentType : MimeTypeDetector::fromString($content), 'name' => Strings::fixEncoding(basename($file)), 'content' => rtrim(chunk_split(base64_encode($content), self::LINE_LENGTH, self::EOL)));
     return $attachment;
 }
예제 #3
0
 /**
  * The data: URI generator.
  * @param  string
  * @param  string
  * @return string
  */
 public static function dataStream($data, $type = NULL)
 {
     if ($type === NULL) {
         $type = Nette\Utils\MimeTypeDetector::fromString($data);
     }
     return 'data:' . ($type ? "{$type};" : '') . 'base64,' . base64_encode($data);
 }
예제 #4
0
파일: Message.php 프로젝트: bazo/Tatami
 /**
  * Creates file MIME part.
  * @return MimePart
  */
 private function createAttachment($file, $content, $contentType, $disposition)
 {
     $part = new MimePart();
     if ($content === NULL) {
         $content = file_get_contents($file);
         if ($content === FALSE) {
             throw new Nette\FileNotFoundException("Unable to read file '{$file}'.");
         }
     } else {
         $content = (string) $content;
     }
     $part->setBody($content);
     $part->setContentType($contentType ? $contentType : Nette\Utils\MimeTypeDetector::fromString($content));
     $part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64);
     $part->setHeader('Content-Disposition', $disposition . '; filename="' . Strings::fixEncoding(basename($file)) . '"');
     return $part;
 }
예제 #5
0
str_replace($search,$replacement,$subject);}static
function
dataStream($data,$type=NULL){if($type===NULL){$type=Nette\Utils\MimeTypeDetector::fromString($data,NULL);}return'data:'.($type?"$type;":'').'base64,'.base64_encode($data);}static
예제 #6
0
UnknownImageFileException("Unknown image type or file '$file' not found.");}}static
function
getFormatFromString($s){$types=array('image/jpeg'=>self::JPEG,'image/gif'=>self::GIF,'image/png'=>self::PNG);$type=Utils\MimeTypeDetector::fromString($s);return
isset($types[$type])?$types[$type]:NULL;}static
예제 #7
0
 /**
  * Returns the MIME content type of file.
  *
  * @param  string
  *
  * @return string
  */
 public static function fromString($data)
 {
     return Nette\Utils\MimeTypeDetector::fromString($data);
 }
예제 #8
0
파일: Media.php 프로젝트: lucien144/Restful
 /**
  * @param string $content
  * @param string|NULL $contentType
  */
 public function __construct($content, $contentType = NULL)
 {
     $this->content = $content;
     $this->contentType = $contentType ? $contentType : MimeTypeDetector::fromString($content);
 }