Created on 23/01/2008 14:59 by Tobias Tom
<?php
function validate_extension
( $filename,
$validExtensions =
array() ){ // if no extensions given, use the default ones
if ( empty( $validExtensions ) ) { $validExtensions =
array('zip',
'rar',
'jpg',
'jpeg',
'gif',
'bmp');
}
// find the last dot inside the filename
$dotPos =
strrpos( $filename,
'.' );
// if no dot was found, the extension is not valid
if ( false === $dotPos ) { return false; }
// get the extension, be sure the dot is not included, and be sure
the
// string gets to lowercase
$extension =
substr( $filename,
( $dotPos +
1 ) );
// when the extension is inside the array, it is valid
return in_array( $extension,
$validExtensions );
}