note 93050 added to function.mime-content-type

From: Date: Thu, 20 Aug 2009 19:04:28 +0000
Subject: note 93050 added to function.mime-content-type
Groups: php.notes 
Request: Send a blank email to php-notes+get-159717@lists.php.net to get a copy of this message
john dot howard at prismmg dot com's tip contains a bug. Change the regular expression from $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext\s)/i"; to $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext)/i"; Working version <?php function get_mime_type($filename,$mimePath = '../etc') { $fileext = substr(strrchr($filename, '.'), 1); if (empty($fileext)) return (false); $regex = "/^([\w\+\-\.\/]+)\s+(\w+\s)*($fileext)/i"; $lines = file("$mimePath/mime.types", FILE_IGNORE_NEW_LINES); foreach($lines as $line) { if (substr($line, 0, 1) == '#') continue; // skip comments if (!preg_match($regex, $line, $matches)) continue; // no match to the extension return ($matches[1]); } return (false); // no match at all } ?> ---- Server IP: 212.63.193.10 Probable Submitter: 85.229.134.52 ---- Manual Page -- http://www.php.net/manual/en/function.mime-content-type.php Edit -- https://master.php.net/note/edit/93050 Del: integrated -- https://master.php.net/note/delete/93050/integrated Del: useless -- https://master.php.net/note/delete/93050/useless Del: bad code -- https://master.php.net/note/delete/93050/bad+code Del: spam -- https://master.php.net/note/delete/93050/spam Del: non-english -- https://master.php.net/note/delete/93050/non-english Del: in docs -- https://master.php.net/note/delete/93050/in+docs Del: other reasons-- https://master.php.net/note/delete/93050 Reject -- https://master.php.net/note/reject/93050 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#159717) next »