note 93050 deleted from function.mime-content-type by danbrown

From: Date: Fri, 21 Aug 2009 13:34:35 +0000
Subject: note 93050 deleted from function.mime-content-type by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-159742@lists.php.net to get a copy of this message
Note Submitter: herlitz ---- 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 } ?>

« previous php.notes (#159742) next »