Upload security check

Im using te fileReference class to upload documents, the problem I have is that flash doesnt send the mime type and I want to validate that the mime type is correct for security reasons.

Anybody knows a fix to this?

The code works in a regular html form but not with the fileReference class

<?php
if (!empty($_FILES['Filedata']['name'])){ 
$fil = $_FILES['Filedata']['name'];
if (preg_match("/\.(?:txt|doc|pdf)$/i", $fil)){ 
  $mime = $_FILES['Filedata']['type']; 
  if($mime == "application/msword" || $mime == "text/plain" || $mime == "application/pdf") { 
$timeStamp = time();
 $uploadDir = "files/";
 $uploadFile = $uploadDir ."$timeStamp-". $_FILES['Filedata']['name'];
 move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
  }
 } 
}
?>