Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine excel file mime type

I need determine what is type of uploaded file

When upload .xlsx file, this code:

 echo $_FILES['uploaded_file']['type']."<br>";  
 echo mime_content_type($_FILES['uploaded_file']['tmp_name']);

returns:

application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.ms-excel

As I know (from here PHP xls, xlsx, ppt, pptx headers), application/vnd.ms-excel is not .xlsx, but .xls file mime type.

So, why returns mime_content_type() function application/vnd.ms-excel for .xlsx file? where the truth?

like image 324
Oto Shavadze Avatar asked Dec 05 '22 11:12

Oto Shavadze


1 Answers

Use FileInfo instead of mime_content_type (which is deprecated).

Regarding mime-types and extensions,

application/vnd.ms-excel                                          xls xlb xlt
application/vnd.ms-excel.addin.macroEnabled.12                    xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12             xlsb
application/vnd.ms-excel.sheet.macroEnabled.12                    xlsm
application/vnd.ms-excel.template.macroEnabled.12                 xltm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx

(available at /etc/mime.types in your linux webserver)

like image 124
tucuxi Avatar answered Dec 09 '22 14:12

tucuxi