86 if (isset($this->file->headers[
'content-type']))
88 if (!isset($this->file->headers[
'content-encoding'])
89 && ($this->file->headers[
'content-type'] ===
'text/plain'
90 || $this->file->headers[
'content-type'] ===
'text/plain; charset=ISO-8859-1'
91 || $this->file->headers[
'content-type'] ===
'text/plain; charset=iso-8859-1'
92 || $this->file->headers[
'content-type'] ===
'text/plain; charset=UTF-8'))
97 if (($pos = strpos($this->file->headers[
'content-type'],
';')) !==
false)
99 $official = substr($this->file->headers[
'content-type'], 0, $pos);
103 $official = $this->file->headers[
'content-type'];
105 $official = trim(strtolower($official));
107 if ($official ===
'unknown/unknown'
108 || $official ===
'application/unknown')
112 elseif (substr($official, -4) ===
'+xml'
113 || $official ===
'text/xml'
114 || $official ===
'application/xml')
118 elseif (substr($official, 0, 6) ===
'image/')
120 if ($return = $this->
image())
129 elseif ($official ===
'text/html')
151 if (substr($this->file->body, 0, 2) ===
"\xFE\xFF"
152 || substr($this->file->body, 0, 2) ===
"\xFF\xFE"
153 || substr($this->file->body, 0, 4) ===
"\x00\x00\xFE\xFF"
154 || substr($this->file->body, 0, 3) ===
"\xEF\xBB\xBF")
158 elseif (preg_match(
'/[\x00-\x08\x0E-\x1A\x1C-\x1F]/', $this->file->body))
160 return 'application/octect-stream';
175 $ws = strspn($this->file->body,
"\x09\x0A\x0B\x0C\x0D\x20");
176 if (strtolower(substr($this->file->body, $ws, 14)) ===
'<!doctype html'
177 || strtolower(substr($this->file->body, $ws, 5)) ===
'<html'
178 || strtolower(substr($this->file->body, $ws, 7)) ===
'<script')
182 elseif (substr($this->file->body, 0, 5) ===
'%PDF-')
184 return 'application/pdf';
186 elseif (substr($this->file->body, 0, 11) ===
'%!PS-Adobe-')
188 return 'application/postscript';
190 elseif (substr($this->file->body, 0, 6) ===
'GIF87a'
191 || substr($this->file->body, 0, 6) ===
'GIF89a')
195 elseif (substr($this->file->body, 0, 8) ===
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
199 elseif (substr($this->file->body, 0, 3) ===
"\xFF\xD8\xFF")
203 elseif (substr($this->file->body, 0, 2) ===
"\x42\x4D")
207 elseif (substr($this->file->body, 0, 4) ===
"\x00\x00\x01\x00")
209 return 'image/vnd.microsoft.icon';
224 if (substr($this->file->body, 0, 6) ===
'GIF87a'
225 || substr($this->file->body, 0, 6) ===
'GIF89a')
229 elseif (substr($this->file->body, 0, 8) ===
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
233 elseif (substr($this->file->body, 0, 3) ===
"\xFF\xD8\xFF")
237 elseif (substr($this->file->body, 0, 2) ===
"\x42\x4D")
241 elseif (substr($this->file->body, 0, 4) ===
"\x00\x00\x01\x00")
243 return 'image/vnd.microsoft.icon';
258 $len = strlen($this->file->body);
259 $pos = strspn($this->file->body,
"\x09\x0A\x0D\x20");
263 switch ($this->file->body[$pos])
269 $pos += strspn($this->file->body,
"\x09\x0A\x0D\x20", $pos);
280 if (substr($this->file->body, $pos, 3) ===
'!--')
283 if ($pos < $len && ($pos = strpos($this->file->body,
'-->', $pos)) !==
false)
292 elseif (substr($this->file->body, $pos, 1) ===
'!')
294 if ($pos < $len && ($pos = strpos($this->file->body,
'>', $pos)) !==
false)
303 elseif (substr($this->file->body, $pos, 1) ===
'?')
305 if ($pos < $len && ($pos = strpos($this->file->body,
'?>', $pos)) !==
false)
314 elseif (substr($this->file->body, $pos, 3) ===
'rss'
315 || substr($this->file->body, $pos, 7) ===
'rdf:RDF')
317 return 'application/rss+xml';
319 elseif (substr($this->file->body, $pos, 4) ===
'feed')
321 return 'application/atom+xml';