note 94279 added to function.mime-content-type

From: Date: Mon, 26 Oct 2009 23:43:49 +0000
Subject: note 94279 added to function.mime-content-type
Groups: php.notes 
Request: Send a blank email to php-notes+get-162134@lists.php.net to get a copy of this message
The function get_mime_type() in the previous note only works properly if mime.types is formatted as Windows text. The updated version below corrects this problem. Thanks to Mike for pointing this out. <?php function get_mime_type($filename, $mimePath = '../etc') { $fileext = substr(strrchr($filename, '.'), 1); if (empty($fileext)) return (false); $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext\s)/i"; $lines = file("$mimePath/mime.types"); foreach($lines as $line) { if (substr($line, 0, 1) == '#') continue; // skip comments $line = rtrim($line) . " "; if (!preg_match($regex, $line, $matches)) continue; // no match to the extension return ($matches[1]); } return (false); // no match at all } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 67.101.123.7 ---- Manual Page -- http://www.php.net/manual/en/function.mime-content-type.php Edit -- https://master.php.net/note/edit/94279 Del: integrated -- https://master.php.net/note/delete/94279/integrated Del: useless -- https://master.php.net/note/delete/94279/useless Del: bad code -- https://master.php.net/note/delete/94279/bad+code Del: spam -- https://master.php.net/note/delete/94279/spam Del: non-english -- https://master.php.net/note/delete/94279/non-english Del: in docs -- https://master.php.net/note/delete/94279/in+docs Del: other reasons-- https://master.php.net/note/delete/94279 Reject -- https://master.php.net/note/reject/94279 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#162134) next »