Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is MIME type different when using different PC but with same config?

I created a function to check the file extension of and imported Excel file. I have run same source on 2 different PCs.

PC-1 Configuration:

  • Win 7 64bit
  • XAMPP with PHP 7.0.x
  • Browser Google Chrome
  • Microsoft Office 2013 installed

PC-2 Configuration:

  • Win 10 64bit
  • XAMPP with PHP 7.1.x
  • Browser Google Chrome
  • Open Office installed. Not install MS Office

My Excel file was created by Google Spreadsheet and exported as an MS Office file with extension .xlsx.

In PC-1, when I debug the $_FILES['file']['type']; value I get the extension:

'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

Yet on PC-2, I received:

'application/octet-stream'

My question is: Why with same source, same import file, just different environments, does the debug output show a different file extension? Is the cause installing MS Office?

like image 638
TommyDo Avatar asked Mar 10 '17 03:03

TommyDo


People also ask

What determines MIME type?

MIME types are defined by three attributes: language (lang), encoding (enc), and content-type (type). At least one of these attributes must be present for each type. The most commonly used attribute is type. The server frequently considers the type when deciding how to generate the response to the client.

How do I fix MIME type errors?

To Solve MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled ErrorJust make Sure Your File name and the name You are Using in Link Tag Both Are Same. For Example my File name is style.

Can a file have multiple MIME types?

Multiple MIME types can use one extension. For example, if your organization uses multiple versions of a program, you can define a MIME type for each version; however, file names of all versions use the same extension.

How does browser determine MIME type?

A browser usually identifies a resource's MIME type by observing the Content-Type response header in an HTTP response. Sometimes, developers set values for Content-Type headers that are not appropriate for the response's content.


1 Answers

It's because Microsoft office isn't installed on PC 2.
So it Chrome doesn't know how to interpret.
Octet-stream is a last ditch attempt to interpret.
This post goes into more detail and there's a way you can tweak registry to perhaps achieve same result.

like image 53
JGFMK Avatar answered Oct 29 '22 20:10

JGFMK