[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Model of an Attachment 5 */ 6 class MimeMailParser_attachment { 7 8 /** 9 * @var $filename Filename 10 */ 11 public $filename; 12 /** 13 * @var $content_type Mime Type 14 */ 15 public $content_type; 16 /** 17 * @var $content File Content 18 */ 19 private $content; 20 /** 21 * @var $extension Filename extension 22 */ 23 private $extension; 24 /** 25 * @var $content_disposition Content-Disposition (attachment or inline) 26 */ 27 public $content_disposition; 28 /** 29 * @var $headers An Array of the attachment headers 30 */ 31 public $headers; 32 33 private $stream; 34 35 public function __construct($filename, $content_type, $stream, $content_disposition = 'attachment', $headers = array()) { 36 $this->filename = $filename; 37 $this->content_type = $content_type; 38 $this->stream = $stream; 39 $this->content = null; 40 $this->content_disposition = $content_disposition; 41 $this->headers = $headers; 42 } 43 44 /** 45 * retrieve the attachment filename 46 * @return String 47 */ 48 public function getFilename() { 49 return $this->filename; 50 } 51 52 /** 53 * Retrieve the Attachment Content-Type 54 * @return String 55 */ 56 public function getContentType() { 57 return $this->content_type; 58 } 59 60 /** 61 * Retrieve the Attachment Content-Disposition 62 * @return String 63 */ 64 public function getContentDisposition() { 65 return $this->content_disposition; 66 } 67 68 /** 69 * Retrieve the Attachment Headers 70 * @return String 71 */ 72 public function getHeaders() { 73 return $this->headers; 74 } 75 76 /** 77 * Retrieve the file extension 78 * @return String 79 */ 80 public function getFileExtension() { 81 if (!$this->extension) { 82 $ext = substr(strrchr($this->filename, '.'), 1); 83 if ($ext == 'gz') { 84 // special case, tar.gz 85 // todo: other special cases? 86 $ext = preg_match("/\.tar\.gz$/i", $ext) ? 'tar.gz' : 'gz'; 87 } 88 $this->extension = $ext; 89 } 90 return $this->extension; 91 } 92 93 /** 94 * Read the contents a few bytes at a time until completed 95 * Once read to completion, it always returns false 96 * @return String 97 * @param $bytes Int[optional] 98 */ 99 public function read($bytes = 2082) { 100 return feof($this->stream) ? false : fread($this->stream, $bytes); 101 } 102 103 /** 104 * Retrieve the file content in one go 105 * Once you retrieve the content you cannot use MimeMailParser_attachment::read() 106 * @return String 107 */ 108 public function getContent() { 109 if ($this->content === null) { 110 fseek($this->stream, 0); 111 while(($buf = $this->read()) !== false) { 112 $this->content .= $buf; 113 } 114 } 115 return $this->content; 116 } 117 118 /** 119 * Allow the properties 120 * MimeMailParser_attachment::$name, 121 * MimeMailParser_attachment::$extension 122 * to be retrieved as public properties 123 * @param $name Object 124 */ 125 public function __get($name) { 126 if ($name == 'content') { 127 return $this->getContent(); 128 } else if ($name == 'extension') { 129 return $this->getFileExtension(); 130 } 131 return null; 132 } 133 134 } 135 136 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |