note 13584 added to function.filetype.php
| From: | darrylbleau at submersion dot com | Date: | Fri, 22 Jun 2001 17:44:23 +0000 |
| Subject: | note 13584 added to function.filetype.php | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14566@lists.php.net to get a copy of this message | ||
A function you can change to return any filetype you want:
first use philikon@gmx.net's code to give the function the file ext, his code is shown here:
function get_file_ext( $filename ) {
ereg( ".*\.([a-zA-z0-9]{0,5})$", $filename, $regs );
return( $regs[1] );
}
and pass that to this:
function get_file_type($f_ext) {
$image_exts = array (".jpg", ".gif", ".png");
$text_exts = array (".htm", ".html", ".txt");
$arr_size = sizeof($image_exts);
for($gft_count=0;$gft_count<$arr_size;$gft_count++){
if ($image_exts[$gft_count] == $f_ext) {
$file_type = "image";
}
}
$arr_size = sizeof($text_exts);
for ($gft_count=0;$gft_count<$arr_size;$gft_count++){
if ($text_exts[$gft_count] == $f_ext) {
$file_type = "text";
}
}
if ($file_type = "") { $file_type = "unknown"; }
return( $file_type );
}
change the arrays to whatever you're looking for.
http://www.php.net/manual/en/function.filetype.php