/** * Creates file MIME part. * @return MimePart */ private function createAttachment($file, $content, $contentType, $disposition) { $part = new MimePart(); if ($content === NULL) { $content = @file_get_contents($file); // intentionally @ if ($content === FALSE) { throw new Nette\FileNotFoundException("Unable to read file '{$file}'."); } } else { $content = (string) $content; } $part->setBody($content); $part->setContentType($contentType ? $contentType : finfo_buffer(finfo_open(FILEINFO_MIME_TYPE), $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; }
/** * 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; }