// Checking file types of the uploaded file with known mime types list to prevent uploading unwanted files
if(isset($_FILES) && count($_FILES)) {
require_once BASEDIR.'includes/mimetypes_include.php';
$mime_types = mimeTypes();
foreach($_FILES as $each) {
if(isset($each['name']) && strlen($each['tmp_name'])) {
$file_info = pathinfo($each['name']);
$extension = $file_info['extension'];
if(array_key_exists($extension, $mime_types)) {
//An extension may have more than one mime type
if(is_array($mime_types[$extension])) {
//We should check each extension one by one
$valid_mimetype = false;
foreach($mime_types[$extension] as $each_mimetype) {
//If we have a match, we set the value to true and break the loop
if($each_mimetype==$each['type']) {
$valid_mimetype = true;
break;
}
}
if(!$valid_mimetype) {
die('Prevented an unwanted file upload attempt!');
}
unset($valid_mimetype);
} else {
if($mime_types[$extension]!=$each['type']) {
die('Prevented an unwanted file upload attempt!');
}
}
} /*else { //Let's disable this for now
//almost impossible with provided array, but we throw an error anyways
die('Unknown file type');
}*/
unset($file_info,$extension);
}
}
unset($mime_types);
}
Category Forum
Suspected Bugs and Errors - 8Labels
None yet
Statistics
5 participants
Notifications
You are not receiving notifications from this thread.
Related Questions