Path: blob/master/externals/mimemailparser/attachment.class.php
12240 views
<?php12/**3* Model of an Attachment4*/5class MimeMailParser_attachment {67/**8* @var $filename Filename9*/10public $filename;11/**12* @var $content_type Mime Type13*/14public $content_type;15/**16* @var $content File Content17*/18private $content;19/**20* @var $extension Filename extension21*/22private $extension;23/**24* @var $content_disposition Content-Disposition (attachment or inline)25*/26public $content_disposition;27/**28* @var $headers An Array of the attachment headers29*/30public $headers;3132private $stream;3334public function __construct($filename, $content_type, $stream, $content_disposition = 'attachment', $headers = array()) {35$this->filename = $filename;36$this->content_type = $content_type;37$this->stream = $stream;38$this->content = null;39$this->content_disposition = $content_disposition;40$this->headers = $headers;41}4243/**44* retrieve the attachment filename45* @return String46*/47public function getFilename() {48return $this->filename;49}5051/**52* Retrieve the Attachment Content-Type53* @return String54*/55public function getContentType() {56return $this->content_type;57}5859/**60* Retrieve the Attachment Content-Disposition61* @return String62*/63public function getContentDisposition() {64return $this->content_disposition;65}6667/**68* Retrieve the Attachment Headers69* @return String70*/71public function getHeaders() {72return $this->headers;73}7475/**76* Retrieve the file extension77* @return String78*/79public function getFileExtension() {80if (!$this->extension) {81$ext = substr(strrchr($this->filename, '.'), 1);82if ($ext == 'gz') {83// special case, tar.gz84// todo: other special cases?85$ext = preg_match("/\.tar\.gz$/i", $ext) ? 'tar.gz' : 'gz';86}87$this->extension = $ext;88}89return $this->extension;90}9192/**93* Read the contents a few bytes at a time until completed94* Once read to completion, it always returns false95* @return String96* @param $bytes Int[optional]97*/98public function read($bytes = 2082) {99return feof($this->stream) ? false : fread($this->stream, $bytes);100}101102/**103* Retrieve the file content in one go104* Once you retrieve the content you cannot use MimeMailParser_attachment::read()105* @return String106*/107public function getContent() {108if ($this->content === null) {109fseek($this->stream, 0);110while(($buf = $this->read()) !== false) {111$this->content .= $buf;112}113}114return $this->content;115}116117/**118* Allow the properties119* MimeMailParser_attachment::$name,120* MimeMailParser_attachment::$extension121* to be retrieved as public properties122* @param $name Object123*/124public function __get($name) {125if ($name == 'content') {126return $this->getContent();127} else if ($name == 'extension') {128return $this->getFileExtension();129}130return null;131}132133}134135?>136137138