Ejemplo n.º 1
0
 /**
  * Constructor
  *
  * @param \BLW\Type\IFile $File
  *            File to attatch.
  * @param string $Name
  *            [optional] File name (basename).
  * @param string $Type
  *            [optional] File mime type.
  */
 public function __construct(IFile $File, $Name = null, $Type = null)
 {
     // Open file if it is not readable
     if (!$File->isReadable()) {
         try {
             $File->openFile();
         } catch (FileException $e) {
             throw new FileException($File->getPathname(), null, $e->getCode(), $e);
         }
     }
     // IContainer constructor
     parent::__construct(IPart::HEADER, 'string');
     // Ensure $Name and $Type are set / not empty
     $Name = @substr($Name, 0) ?: $File->getBasename();
     $Type = @substr($Type, 0) ?: $File->getMimetype();
     // Host
     $Host = @$_SERVER['HTTP_HOST'] ?: @$_SERVER['SERVER_NAME'] ?: @$_SERVER['SERVER_ADDR'] ?: '0.0.0.0';
     $Host = "http://{$Host}/";
     // Attachment Headers
     parent::offsetSet('Content-Type', new ContentType($Type, array('name' => $Name)));
     parent::offsetSet('Content-Transfer-Encoding', new ContentTransferEncoding('base64'));
     parent::offsetSet('Content-Disposition', new ContentDisposition('inline', array('filename' => $Name)));
     parent::offsetSet('Content-ID', new ContentID());
     parent::offsetSet('Content-Location', new ContentLocation(new GenericURI("/{$Name}")));
     parent::offsetSet('Content-Base', new ContentBase(new GenericURI($Host)));
     // Attachment content
     parent::offsetSet('Content', $this->format($File->getContents(), self::CHUNKLEN) . $this->_CRLF);
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @param string $Field
  *            Label of field.
  * @param \BLW\Type\IFile $File
  *            File to attatch.
  * @param string $Name
  *            File name (basename).
  * @param string $Type
  *            File mime type.
  */
 public function __construct($Field, IFile $File, $Name = null, $Type = null)
 {
     // Is $Field not a string?
     if (!is_string($Field) && !is_callable(array($Field, '__toString'))) {
         throw new InvalidArgumentException(0);
         // Open file if it is not readable
     } elseif (!$File->isReadable()) {
         try {
             $File->openFile();
         } catch (FileException $e) {
             throw new FileException($File->getPathname(), null, $e->getCode(), $e);
         }
     }
     // IContainer constructor
     parent::__construct(IPart::HEADER, 'string');
     $Field = strval($Field);
     // Get $Name and $Type from file if not set
     $Type = $Type ?: $File->getMimetype();
     $Name = $Name ?: $File->getBasename();
     // File Headers
     parent::offsetSet('Content-Disposition', new ContentDisposition('form-data', array('name' => $Field, 'filename' => $Name)));
     parent::offsetSet('Content-Type', new ContentType($Type));
     parent::offsetSet('Content-Transfer-Encoding', new ContentTransferEncoding('binary'));
     // File content
     parent::offsetSet('Content', $this->format($File->getContents(), self::CHUNKLEN) . $this->_CRLF);
 }
Ejemplo n.º 3
0
 /**
  * Constructor
  *
  * @param \BLW\Type\IFile $File
  *            File to attatch.
  * @param string $Name
  *            File name (basename).
  * @param string $Type
  *            File mime type.
  */
 public function __construct(IFile $File, $Name = null, $Type = null)
 {
     // Open file if it is not readable
     if (!$File->isReadable()) {
         try {
             $File->openFile();
         } catch (FileException $e) {
             throw new FileException($File->getPathname(), null, $e->getCode(), $e);
         }
     }
     // IContainer constructor
     parent::__construct(IPart::HEADER, 'string');
     // Ensure $Name and $Type are set / not empty
     $Name = @substr($Name, 0) ?: $File->getBasename();
     $Type = @substr($Type, 0) ?: $File->getMimetype();
     // Attachment Headers
     parent::offsetSet('Content-Type', new ContentType($Type, array('name' => $Name)));
     parent::offsetSet('Content-Transfer-Encoding', new ContentTransferEncoding('base64'));
     parent::offsetSet('Content-Disposition', new ContentDisposition('attachment', array('filename' => $Name)));
     // Attachment content
     parent::offsetSet('Content', $this->format($File->getContents(), self::CHUNKLEN) . $this->_CRLF);
 }