In my last post, I described how to install the Fileinfo PECL module on a Media Temple (dv) server, but I didn't really talk about what it does, why one might want to install it and how to use it.

The methods/functions in the Fileinfo PHP extension "try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach, the heuristics used do a very good job."1 (Note that this module replaces the Mimetype module.)

Read the rest of this entry »

This post describes how to install the PECL Fileinfo extension on a Media Temple dedicated virtual (dv) 3.5 server. A future post will describe what the Fileinfo extension does and why you might want to install it.

Read the rest of this entry »

In PHP, the MIME type is set through the header function (note the header function must be called prior to outputting anything to the browser).

To correctly serve XML, call the header function with the following arguments:

header('Content-Type: text/xml; charset=utf-8');

Correctly serving XHTML is a bit more complicated. The $_SERVER array contains the server variables, allowing us to interrogate the Accept HTTP header:

header('Vary: Accept');
if (stristr($_SERVER[HTTP_ACCEPT], 'application/xhtml+xml')) {
header('Content-Type: application/xhtml+xml; charset=utf-8');
} else {
header('Content-Type: text/html; charset=utf-8');
}

More information on correctly serving XHTML.