note 21334 deleted from function.filetype by sniper
| From: | sniper@php.net | Date: | Fri, 31 Oct 2003 13:36:41 +0000 |
| Subject: | note 21334 deleted from function.filetype by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59584@lists.php.net to get a copy of this message | ||
Note Submitter: gareth@raveroom.com
----
much faster/easier way to get the type from a list of known types based on the file extension.
using the ereg example already given....
function get_file_type($filename) {
ereg( ".*\.([a-zA-z0-9]{0,5})$", $filename, $regs );
$f_ext = $regs[1];
$types['image'] = array ('jpg', 'gif','png');
$types['text'] = array ('html', 'htm', 'text');
$types['music'] = array ('mp3', 'mpeg3');
foreach ($types as $k => $v) {
if (in_array($f_ext, $v)) {
return $k;
break;
}
}
echo 'type-unknown';
}
and in your readdir loop you do:
get_file_type($file)
little... yellow... different...