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

1

6

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?

Hadsall answered 10/3, 2017 at 3:38 Comment(3)
It's server-side that reports the MIME type, therefore it is not related to what software installed in the client-side.Non
Thank Leigh for fixing my English mistakes. Raptor: So what is the cause of this situation.Hadsall
I guess it's about PHP 7.1 vs 7.0's difference. Can you use finfo_file() to verify the MIME type again?Non
R
1

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.

Rolf answered 9/7, 2017 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.