note 35114 deleted from function.mime-content-type by nlopess

From: Date: Sat, 03 Jan 2004 10:13:12 +0000
Subject: note 35114 deleted from function.mime-content-type by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62849@lists.php.net to get a copy of this message
Note Submitter: arend@auton.nl ---- I've written my own MIME library in PHP5 which follows the Shared MIME Database specification as explained further on http://www.freedesktop.org/standards/shared-mime-info-spec/. You can find the file on http://www.liacs.nl/~dvbeelen/MIME.php.txt. The library contains two functions: string mimeType(string $filename, bool $openfile = true) string mimeDescription(string $mimetype, string $language = 'en') The first function is passed a file name. First it will try to determine the mimetype using globbing rules (purely based on the filename and extension). If it finds a match it will return that mimetype. If it does not find a match and $openfile is false, it will return an empty string. If $openfile is true, however (which is the default) it will actually open the file and apply magic rules to determine the mimetype. If even this fails it will return either 'application/octet-stream' or 'text/plain' based on whether the file is binary or text. On error the function will always return an empty string. The second function is passed a mimetype and will return the textual description of the mimetype. If $language is specified it will try find the description in the given language. If that fails however, the English description is still returned. If the specified mimetype can't be found at all, an empty string is returned. I hope you find these functions useful and would like to receive some feedback if people decide to use them. Thanks. To use these functions you need PHP5 and the Shared MIME Database from the above URL.

« previous php.notes (#62849) next »