4

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?

chudst
  • 139
  • 3
  • 12

2 Answers2

2

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...}
Jonas
  • 6,915
  • 8
  • 35
  • 53
Nadeem Shaikh
  • 289
  • 2
  • 13
  • Hi, thank you for your effort :) But it's not working :( (And before that it didn't write me any error (just 'my' message, that its not supported file), now with your solution its writing me: 'Warning: mime_content_type(): Can only process string or stream arguments in /data/web/virtuals/25/virtual/www/subdom/avcr/vrstvy/upload.php on line 124'. – chudst May 05 '17 at 12:06
0

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