Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Microsoft 10 Edge browser Mime Types php

When checking the file mime types of files being uploaded in Microsoft 10's Edge browser, I get this Mime Type for .doc files:

application/octet-stream

Apparently this indicates "arbitrary binary data": Do I need Content-Type: application/octet-stream for file download?

On other browsers I get application/msword

Is there a new way mime types are handled for .doc files for the Edge browser, and maybe other mime types I need to be aware of?

Update:

I was grabbing the mime type using php's $_FILES['uploadName']['type']

like image 872
Andrew Avatar asked Sep 26 '22 15:09

Andrew


1 Answers

I found that by using this instead, I get the correct mime type:

$finfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->file($_FILES['uploadName']['tmp_name'][$key]);

And as Martin mentioned in a comment above:

You should not grab the MIME type from the data given in $_FILE as this is extremely flaky and up for interpretation, as you are experiencing. Instead, do a new analysis of the uploaded temporary file, Use finfo() or similar.

like image 70
Andrew Avatar answered Oct 05 '22 23:10

Andrew