# Adding new MIME types for the CLI web server

- Thread: https://externals.io/message/69872
- Original archive: https://news-web.php.net/php.internals/69872
- Started by Christopher Jones on 2013-10-25T19:55:07+00:00
- Messages: 11
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #69872 — Christopher Jones — 2013-10-25T19:55:07+00:00

URL: https://externals.io/message/69872#69872

I'm planning on adding some MIME type to the CLI web server.

For PHP 5.5.5 CLI web server I added the .pdf MIME type.  I was using
the webserver for a conference exhibition hall demo and needed to
present a PDF.

Some other multi-media types could be useful in future situations, and
in general.  I'm thinking of adding these to PHP 5.5.6 & master:

        { "avi",  "video/x-msvideo" },
        { "flv",  "video/x-flv" },
        { "swf",  "application/x-shockwave-flash" },
        { "qt",   "video/quicktime" },
        { "mov",  "video/quicktime" },
        { "mp3",  "audio/mpeg" },
        { "mp4",  "video/mpeg" },
        { "mpg",  "video/mpeg" },
        { "mpeg", "video/mpeg" },
        { "wav",  "audio/wav" },

Notes:

- A router can be used to add to, or override, the MIME type lookups,
   see http://php.net/manual/en/features.commandline.webserver.php

- The web server code does a linear lookup through the MIME table,
   defaulting on failure to returning "application/octet-stream".

-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #69881 — Dan Ackroyd — 2013-10-26T17:39:21+00:00

URL: https://externals.io/message/69872#69881 · In reply to: #69872

Hi,

Christopher Jones wrote:
> I'm thinking of adding these to PHP 5.5.6 & master:
> { "mp4",  "video/mpeg" },

FYI that's not the correct mime type for mp4 -
http://www.rfc-editor.org/rfc/rfc4337.txt

The exact mime type depends on the content of the file, but
'video/mp4' would be more appropriate than 'video/mpeg'.

cheers
Dan

On Fri, Oct 25, 2013 at 7:55 PM, Christopher Jones
<christopher.jones@oracle.com> wrote:
> I'm planning on adding some MIME type to the CLI web server.
>
> For PHP 5.5.5 CLI web server I added the .pdf MIME type.  I was using
> the webserver for a conference exhibition hall demo and needed to
> present a PDF.
>
> Some other multi-media types could be useful in future situations, and
> in general.  I'm thinking of adding these to PHP 5.5.6 & master:
>
>        { "avi",  "video/x-msvideo" },
>        { "flv",  "video/x-flv" },
>        { "swf",  "application/x-shockwave-flash" },
>        { "qt",   "video/quicktime" },
>        { "mov",  "video/quicktime" },
>        { "mp3",  "audio/mpeg" },
>        { "mp4",  "video/mpeg" },
>        { "mpg",  "video/mpeg" },
>        { "mpeg", "video/mpeg" },
>        { "wav",  "audio/wav" },
>
> Notes:
>
> - A router can be used to add to, or override, the MIME type lookups,
>   see http://php.net/manual/en/features.commandline.webserver.php
>
> - The web server code does a linear lookup through the MIME table,
>   defaulting on failure to returning "application/octet-stream".
>
> --
> christopher.jones@oracle.com  http://twitter.com/ghrd
> Free PHP & Oracle book:
> http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #69886 — Christopher Jones — 2013-10-26T22:57:30+00:00

URL: https://externals.io/message/69872#69886 · In reply to: #69881

> Hi,
>
> Christopher Jones wrote:
> > […]
>
> FYI that's not the correct mime type for mp4 -
> http://www.rfc-editor.org/rfc/rfc4337.txt
>
> The exact mime type depends on the content of the file, but
> 'video/mp4' would be more appropriate than 'video/mpeg'.

My mistake.  Thanks for picking it up.

Chris

>
> cheers
> Dan
>
> On Fri, Oct 25, 2013 at 7:55 PM, Christopher Jones
> <christopher.jones@oracle.com> wrote:
> > […]

-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #69986 — Christopher Jones — 2013-10-31T21:01:19+00:00

URL: https://externals.io/message/69872#69986 · In reply to: #69872

> I'm planning on adding some MIME type to the CLI web server.
>
> For PHP 5.5.5 CLI web server I added the .pdf MIME type.  I was using
> the webserver for a conference exhibition hall demo and needed to
> present a PDF.
>
> Some other multi-media types could be useful in future situations, and
> in general.  I'm thinking of adding these to PHP 5.5.6 & master:
>
>         { "avi",  "video/x-msvideo" },
>         { "flv",  "video/x-flv" },
>         { "swf",  "application/x-shockwave-flash" },
>         { "qt",   "video/quicktime" },
>         { "mov",  "video/quicktime" },
>         { "mp3",  "audio/mpeg" },
>         { "mp4",  "video/mpeg" },
>         { "mpg",  "video/mpeg" },
>         { "mpeg", "video/mpeg" },
>         { "wav",  "audio/wav" },
>
> Notes:
>
> - A router can be used to add to, or override, the MIME type lookups,
>    see http://php.net/manual/en/features.commandline.webserver.php
>
> - The web server code does a linear lookup through the MIME table,
>    defaulting on failure to returning "application/octet-stream".
>

I had feedback from one person who suggested adding these:

         { "3gp", "video/3gpp" },    //This is standard video format used for MMS in phones
         { "apk", "application/vnd.android.package-archive" },
         { "avi", "video/x-msvideo" },
         { "bmp", "image/x-ms-bmp" },
         { "csv", "text/comma-separated-values" },
         { "doc", "application/msword" },
         { "docx", "application/msword" },
         { "flac", "audio/flac" },
         { "gz",  "application/x-gzip" },
         { "gzip", "application/x-gzip" },
         { "ics", "text/calendar" },
         { "kml", "application/vnd.google-earth.kml+xml" },
         { "kmz", "application/vnd.google-earth.kmz" },
         { "m4a", "audio/mp4" },
         { "mp3", "audio/mpeg" },
         { "mp4", "video/mp4" },
         { "mpg", "video/mpeg" },
         { "mpeg", "video/mpeg" },
         { "mov", "video/quicktime" },
         { "odp", "application/vnd.oasis.opendocument.presentation" },
         { "ods", "application/vnd.oasis.opendocument.spreadsheet" },
         { "odt", "application/vnd.oasis.opendocument.text" },
         { "oga", "audio/ogg" },
         { "pdf", "application/pdf" },
         { "pptx", "application/vnd.ms-powerpoint" },
         { "pps", "application/vnd.ms-powerpoint" },
         { "qt", "video/quicktime" },
         { "swf", "application/x-shockwave-flash" },
         { "tar", "application/x-tar" },
         { "text", "text/plain" },
         { "tif", "image/tiff" },
         { "wav", "audio/wav" },
         { "wmv", "video/x-ms-wmv" },
         { "xls", "application/vnd.ms-excel" },
         { "xlsx", "application/vnd.ms-excel" },
         { "zip", "application/x-zip-compressed"


The PHP CLI web server 5.5 currrently supports these MIME types natively:

	{ "html", "text/html" },
	{ "htm", "text/html" },
	{ "js", "text/javascript" },
	{ "css", "text/css" },
	{ "gif", "image/gif" },
	{ "jpg", "image/jpeg" },
	{ "jpeg", "image/jpeg" },
	{ "jpe", "image/jpeg" },
	{ "png", "image/png" },
	{ "svg", "image/svg+xml" },
	{ "txt", "text/plain" },
	{ "webm", "video/webm" },
	{ "ogv", "video/ogg" },
	{ "ogg", "audio/ogg" },


Final comments anyone, before I commit next week?

Chris

-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #69987 — Derick Rethans — 2013-10-31T21:32:11+00:00

URL: https://externals.io/message/69872#69987 · In reply to: #69986

> The PHP CLI web server 5.5 currrently supports these MIME types 
> natively:
> 
> 	{ "html", "text/html" },
> 	{ "htm", "text/html" },
> 	{ "js", "text/javascript" },
> 	{ "css", "text/css" },
> 	{ "gif", "image/gif" },
> 	{ "jpg", "image/jpeg" },
> 	{ "jpeg", "image/jpeg" },
> 	{ "jpe", "image/jpeg" },
> 	{ "png", "image/png" },
> 	{ "svg", "image/svg+xml" },
> 	{ "txt", "text/plain" },
> 	{ "webm", "video/webm" },
> 	{ "ogv", "video/ogg" },
> 	{ "ogg", "audio/ogg" },
> 
> 
> Final comments anyone, before I commit next week?

Isn't there a reason why you can't use the fileinfo extension/code for 
this instead? Hardcoding it seems rather strange?

cheers,
Derick

-- 
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine

---

## #69988 — Andrea Faulds — 2013-10-31T21:37:49+00:00

URL: https://externals.io/message/69872#69988 · In reply to: #69987

>
> Isn't there a reason why you can't use the fileinfo extension/code for
> this instead? Hardcoding it seems rather strange?
>

I looked at the manual and `mime_content_type()` is deprecated and tells 
me to use the Fileinfo PECL extension. From which I am led back to the 
parent section, which is for the built-in Fileinfo extension. Looks like 
the manual is out-of-date.

Anyhow, looks like `finfo_file()` works as we'd want, though I feel uneasy 
about guessing filetypes this way. Perhaps we should have several 
explicitly specified ones (.txt as text/plain, .html as text/html, 
etc.), and guess the rest? Especially for ones which it would not 
correctly guess.

Thanks.
-- 
Andrea Faulds
http://ajf.me/

---

## #69989 — Stas Malyshev — 2013-10-31T23:12:36+00:00

URL: https://externals.io/message/69872#69989 · In reply to: #69986

Hi!

> Final comments anyone, before I commit next week?

It looks strange that we have to hardcode so many mimetypes in the code,
and doesn't sound a scalable solution. Can't we make it use data from
fileinfo or some other customizeable table so we don't have to keep all
MIME types hardcoded in the code? Maybe some ability to use Apache's
mime.types file?
-- 
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227

---

## #69990 — Christopher Jones — 2013-10-31T23:51:20+00:00

URL: https://externals.io/message/69872#69990 · In reply to: #69989

> Hi!
>
> > […]
>
> It looks strange that we have to hardcode so many mimetypes in the code,
> and doesn't sound a scalable solution. Can't we make it use data from
> fileinfo or some other customizeable table so we don't have to keep all
> MIME types hardcoded in the code? Maybe some ability to use Apache's
> mime.types file?
>

It isn't scalable, but users can always use a router script to add
additional types so there isn't a real world problem in missing
uncommon extensions.

My idea was to add common extensions to the existing look-up list.  A
quick and straight-forward solution to making the CLI web-server
handle the 80-20 rule.

If someone (ajf?) wants to work on a more comprehensive solution
instead, I have no objection.

Chris

-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #70311 — Mike Willbanks — 2013-11-23T04:22:25+00:00

URL: https://externals.io/message/69872#70311 · In reply to: #69990

Chris,

What is wrong with a more common magic file which  fileinfo utilizes? I
understand the concept of adding common extensions but only as a fallback
to distro behavior.

Regards,

Mike
On Oct 31, 2013 6:52 PM, "Christopher Jones" <christopher.jones@oracle.com>
wrote:

>
>
> 
>
> > […]
> It isn't scalable, but users can always use a router script to add
> additional types so there isn't a real world problem in missing
> uncommon extensions.
>
> My idea was to add common extensions to the existing look-up list.  A
> quick and straight-forward solution to making the CLI web-server
> handle the 80-20 rule.
>
> If someone (ajf?) wants to work on a more comprehensive solution
> instead, I have no objection.
>
> Chris
>
> --
> christopher.jones@oracle.com  http://twitter.com/ghrd
> Free PHP & Oracle book:
> http://www.oracle.com/technetwork/topics/php/
> underground-php-oracle-manual-098250.html

---

## #70313 — Christopher Jones — 2013-11-23T04:39:07+00:00

URL: https://externals.io/message/69872#70313 · In reply to: #70311

> Chris,
>
> What is wrong with a more common magic file which  fileinfo utilizes? I
> understand the concept of adding common extensions but only as a fallback
> to distro behavior.
>
> Regards,
>
> Mike

There's nothing wrong that I know of.  If you have time to implement it,
go ahead.

Chris

-- 
christopher.jones@oracle.com  http://twitter.com/ghrd
Free PHP & Oracle book:
http://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

---

## #70323 — Pierre Joye — 2013-11-23T09:06:56+00:00

URL: https://externals.io/message/69872#70323 · In reply to: #70313

hi,

On Sat, Nov 23, 2013 at 5:39 AM, Christopher Jones
<christopher.jones@oracle.com> wrote:
>
>
> 
> > […]
>
>
> There's nothing wrong that I know of.  If you have time to implement it,
> go ahead.

There is nothing wrong but it may not as easy as it looks.

This file must be available when fiinfo is not enabled (build time) or
loaded. fileinfo ma be shared too (as far as I remember almost all
distros provide it optionally and shared). That's something to keep in
mind while implementing a patch.

Cheers,
-- 
Pierre

@pierrejoye | http://www.libgd.org
