/** * Constructs a new attachment with $fileName and $stream. * * If the $mimeType and $contentType are not specified they are set * to application/octet-stream. * * @param string $fileName * @param resource $stream * @param string $contentType * @param string $mimeType */ public function __construct($fileName, $stream, $contentType = null, $mimeType = null) { parent::__construct($fileName); $this->stream = $stream; if ($contentType != null && $mimeType != null) { $this->contentType = $contentType; $this->mimeType = $mimeType; } else { // default to mimetype application/octet-stream $this->contentType = self::CONTENT_TYPE_APPLICATION; $this->mimeType = "octet-stream"; } }
/** * Constructs a new attachment with $fileName. * * If the $mimeType and $contentType are not specified they are extracted * with the fileinfo extension if it is available, otherwise they are set * to application/octet-stream. * * @param string $fileName * @param string $contentType * @param string $mimeType */ public function __construct($fileName, $contentType = null, $mimeType = null) { parent::__construct($fileName); if ($contentType != null && $mimeType != null) { $this->contentType = $contentType; $this->mimeType = $mimeType; } elseif (ezcBaseFeatures::hasExtensionSupport('fileinfo')) { // get mime and content type $fileInfo = finfo_open(FILEINFO_MIME); $mimeParts = finfo_file($fileInfo, $fileName); if ($mimeParts !== false && strpos($mimeParts, '/') !== false) { list($this->contentType, $this->mimeType) = explode('/', $mimeParts); } else { // default to mimetype application/octet-stream $this->contentType = self::CONTENT_TYPE_APPLICATION; $this->mimeType = "octet-stream"; } finfo_close($fileInfo); } else { // default to mimetype application/octet-stream $this->contentType = self::CONTENT_TYPE_APPLICATION; $this->mimeType = "octet-stream"; } }