4
votes

I'm trying to solve one problem: I want to upload to my website XLS/XLSX file. And I've there for it this condition:

if((mime_content_type($file) == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || mime_content_type($file) == 'application/vnd.ms-excel') && ($extension == 'xls' || $extension == 'XLS' || $extension == 'xlsx' || $extension == 'XLSX')){...upload...}

When I use the XLS/X file (which has been saved directly from MS Excel), it works great. But when I want to upload XLS/X file - which has been saved directly from LibreOffice (not as ODS, but as an XLS/X) - it doesn't work and I can't upload this file.

Thanks for any help!

(And the condition with application/vnd.oasis.opendocument.spreadsheet doesn't work as well.)

Update: Thanks to Dipanwita Kundu I was able to find, which MIME type is used (application/octet-stream) - but its safe to put this as the condition?

2
Try to use `'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.openxmlformats-officedocument.wordprocessingml.document'Dipanwita Kundu
Hi, thanks - but without any effect, it's still not working.chudst
try to print your mime content type I mean echo mime_content_type($file) & check the result.Dipanwita Kundu
As you are checking mime_content_type & allowing file based on mime type, so it has the same risk like other mime typeDipanwita Kundu
Fun fact: LibreOffice 5.4.2.2.0+ doesn't save as application/octet-stream any more. Now it's application/zip because someone thought that made sense.Daniel Quinn

2 Answers

2
votes

try this

if((mime_content_type($file) == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || mime_content_type($file) == 'application/vnd.ms-excel' || mime_content_type($file) == 'application/vnd.openxmlformatsofficedocument.spreadsheetml.sheet') && ($extension == 'xls' || $extension == 'XLS' || $extension == 'xlsx' || $extension == 'XLSX')){...upload...}
0
votes

If you save an file with LibreOffice Calc, then the php mime_content_type($file) return value is 'application/zip'.

Upload xls or xlsx files with codeigniter, mime-type error