/** * The data: URI generator. * @param string * @param string * @return string */ public static function dataStream($data, $type = NULL) { if ($type === NULL) { $type = NMimeTypeDetector::fromString($data, NULL); } return 'data:' . ($type ? "$type;" : '') . 'base64,' . base64_encode($data); }
/** * 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 = NMimeTypeDetector::fromString($s); return isset($types[$type]) ? $types[$type] : NULL; }
/** * Returns the MIME content type of an uploaded file. * @return string */ public function getContentType() { if ($this->isOk() && $this->type === NULL) { $this->type = NMimeTypeDetector::fromFile($this->tmpName); } return $this->type; }
/** * Creates file MIME part. * @return NMailMimePart */ private function createAttachment($file, $content, $contentType, $disposition) { $part = new NMailMimePart; if ($content === NULL) { $content = file_get_contents($file); if ($content === FALSE) { throw new FileNotFoundException("Unable to read file '$file'."); } } else { $content = (string) $content; } $part->setBody($content); $part->setContentType($contentType ? $contentType : NMimeTypeDetector::fromString($content)); $part->setEncoding(preg_match('#(multipart|message)/#A', $contentType) ? self::ENCODING_8BIT : self::ENCODING_BASE64); $part->setHeader('Content-Disposition', $disposition . '; filename="' . NStrings::fixEncoding(basename($file)) . '"'); return $part; }