0

I am trying to allow users to upload outlook email messages saved as .msg files but my error system says the messages are not part of my allowed bunch. I have tried 3 different outlook types but to no avail. What is the correct mime type?

Here is my shortened code.

$whitelist = array('application/outlook','application/msoutlook','application/vnd.ms-outlook');
$errors = false;

if (isset($_POST['submit'])) {

$uniqueid = time().$_SESSION['webuserid'];
$description = htmlspecialchars($_POST['description']);

if (empty($_FILES['file']['name'])) { 

$message = "<b> * No File Selected</b>"; $errors = true; }

if ($_FILES['file']['size'] > 5000000 && !empty($_FILES['file']['name'])) { 

$message = "<b> * 5MB Max Upload</b>"; $errors = true; } 

if (!in_array($_FILES['file']['type'], $whitelist) && !empty($_FILES['file']['name'])) { 

$message = "<b> * PDF, Excel, Outlook Message, Word Format Only</b>"; $errors = true; }

Thanks

bass71982
  • 75
  • 1
  • 10

1 Answers1

1

So why don't you var_dump($_FILES['file']['type']); for a .msg file and see what it says? Then add that to your $whitelist.

You'll probably find the mimetype is application/vnd.msoutlook

TunaMaxx
  • 1,782
  • 12
  • 18
  • Unfortunetely application/vnd.msoutlook didnt work but the var_dump showed "application/octet-stream" as the type. Thanks for your help – bass71982 Aug 27 '14 at 10:35
  • Just beware that `application/octet-stream` is the mime type for a whole class of files that you probably don't want allow, (.exe for example) or anything that a mime type could not be determined for. See here for more info: http://stackoverflow.com/questions/20508788/do-i-need-content-type-application-octet-stream-for-file-download So, you might want to add a file extension check too, just in case. Note the file extension is not a safe file check on it's own. – TunaMaxx Aug 28 '14 at 23:21
  • Checking `$_FILES['file']['type']` isn't a safe approach as the type is set by the browser and can be easily spoofed. A more secure (and reliable) way to do it is to use PHP's fileinfo extension. See here for some examples: http://php.net/manual/en/function.finfo-open.php – alexpls Jan 15 '15 at 00:24