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?

Matt S
  • 14,976
  • 6
  • 57
  • 76
TommyDo
  • 663
  • 8
  • 23
  • It's server-side that reports the MIME type, therefore it is not related to what software installed in the client-side. – Raptor Mar 10 '17 at 04:17
  • Thank Leigh for fixing my English mistakes. Raptor: So what is the cause of this situation. – TommyDo Mar 10 '17 at 04:28
  • 1
    I guess it's about PHP 7.1 vs 7.0's difference. Can you use [finfo_file()](http://php.net/manual/ro/function.finfo-file.php) to verify the MIME type again? – Raptor Mar 10 '17 at 04:30

1 Answers1

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.

JGFMK
  • 8,425
  • 4
  • 58
  • 92