NotionCommotion Posted February 19, 2015 Share Posted February 19, 2015 Could someone please execute the following script. The test.msg file needs to be an MS Outlook file. To create one, open an email using Outlook and save as a msg file. I'm not sure if OpenOffice will work as well. <?php $finfo = finfo_open(FILEINFO_MIME_TYPE); $filetype=finfo_file($finfo, 'test.msg'); echo($filetype); ?> What output did you get? I get application/CDFV2-corrupt. Is that correct? Shouldn't it be application/vnd.ms-outlook? I am running Centos 6. What operating system are you using? Thank you Quote Link to comment Share on other sites More sharing options...
requinix Posted February 19, 2015 Share Posted February 19, 2015 It may very well appear to be a "application/CDFV2-corrupt" file too, whatever that is. If it's not giving you the answer you want then you can do the MIME magic yourself pretty easily. $h = fopen('test.msg', 'rb'); $magic = "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00"; $bytes = fread($h, strlen($magic)); fclose($h); if ($bytes == $magic) { $filetype = 'application/CDFV2-corrupt'; } else { // use finfo } Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 19, 2015 Author Share Posted February 19, 2015 Thanks Requinix, Don't know if I understand the purpose. When using your script on the file in question, $bytes==$magic, so I shouldn't use finfo? But finfo provides the same results (i.e. application/CDFV2-corrupt). My question is what is a application/CDFV2-corrupt mime in the first place? It shouldn't be as far as I know. On a side note, what does the following script do? $bytes = fread($h, strlen("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00")); Quote Link to comment Share on other sites More sharing options...
requinix Posted February 19, 2015 Share Posted February 19, 2015 Silly typo. That line should be $filetype = 'application/vnd.ms-outlook'; On a side note, what does the following script do? $bytes = fread($h, strlen("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00")); That's the basic premise of MIME type detection: read a few bytes from the beginning of the file and look them up in a database. With that code, the "database" is simply "do the first 9 bytes match this known string", and if that's true then the detection result is application/vnd.ms-outlook. finfo is using a more comprehensive database, naturally. It apparently has those same 9 bytes (maybe fewer) except it maps those to be the application/CDFV2-corrupt type. So the idea is to check your own "database" first, since you know that to be accurate, and if there's no match then use the general purpose, 99%-accurate finfo. Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted February 19, 2015 Author Share Posted February 19, 2015 Ah, that makes sense now. So, it appears that finfo is not always accurate. Odd that an Outlook msg file would be in that list. How did you come up with "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1\x00" as the magic string? Guess if there were several file types that finfo doesn't get right (this is the first I found, however), I could check each of them before using finfo easily enough. Also, did you have a chance to use finfo on a Outlook msg file? Wondering if is just my distribution/library. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.