Beispiel #1
0
 /**
  * Construct an attachment with a stream and a name.
  *
  * @param   \Hoa\Stream  $stream      Stream that contains the attachment.
  * @param   string       $name        Name of the attachment (if null, will
  *                                    use the stream basename).
  * @param   string       $mimeType    Force a MIME type.
  * @return  void
  */
 public function __construct(Stream $stream, $name = null, $mimeType = null)
 {
     parent::__construct();
     if (null === $name) {
         if ($stream instanceof Stream\IStream\Pathable) {
             $name = $stream->getBasename();
         } else {
             $name = basename($stream->getStreamName());
         }
     }
     if (null === $mimeType) {
         $mimeType = null;
         try {
             $mime = new Mime($stream);
             $mimeType = $mime->getMime();
         } catch (Mime\Exception $e) {
         }
         if (null === $mimeType) {
             $mimeType = 'application/octet-stream';
         }
     }
     $size = null;
     if ($stream instanceof Stream\IStream\Statable && false !== ($_size = $stream->getSize())) {
         $size = '; size=' . $_size;
     }
     $this['content-type'] = $mimeType;
     $this['content-disposition'] = 'attachment; filename="' . str_replace('"', '-', $name) . '"' . $size;
     $this->setStream($stream);
     return;
 }