0

I need to create a .xls file and assign the correct mimetype to it. A simple header() statement didn't work probably because i'm using PHPGtk.

MSOffice gives me an error when opening the file, it says the content may not reflect the extension of the file, so i immediately thought it could be because of the mime type.

Currently, the code is (in a very malformed html snippet):

$table = '<table><thead><tr><th>Oi</th></tr></thead><tbody><tr><td>opaopaopa</td></tr><tr><td>sjiasiaj</td></tr></tbody></table>';
      $handle = fopen('C:\opa.xls','w+');
      fwrite($handle, $table);
      fclose($handle);
Jorge Guberte
  • 10,464
  • 8
  • 37
  • 56

1 Answers1

2

On Windows, the files don't have mime types. They are identified by their extension only.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • I asked the question because MSOffice gives me an error when opening the file, it says the content may not reflect the extension of the file, so i immediately thought it could be because of the mime type. – Jorge Guberte Sep 12 '11 at 17:19
  • 3
    @jorge: That's because you're writing an html file (without proper `` and `` tags, but are naming it .xls. – Marc B Sep 12 '11 at 17:35
  • @Jorge: It would be advantageous to everyone if you put that information in your question. I'm not criticizing. It's just a thought. – Herbert Sep 12 '11 at 17:57
  • @Marc Yes, but can i set the mime to anything else so Office won't bitch about it? – Jorge Guberte Sep 12 '11 at 20:57
  • 1
    Not on the file itself. You could try putting a `` tag into a `` block, but I don't know if Windows or Office will looking that far into the file before deciding to spit out that error – Marc B Sep 12 '11 at 20:59
  • @Jorge, put .html on the end of it. You can't create an HTML file with an XLS extension and expect Excel to think by default that it is a genuine Excel spreadsheet file. – Brad Sep 12 '11 at 21:09
  • @Brad But i don't need an HTML file. If i needed i'd just change the extension. :P – Jorge Guberte Sep 13 '11 at 14:40
  • @Jorge.... then why are you outputting an HTML file. You have a large disconnect here. Your code itself is outputting HTML, and you are naming it XLS. If you want XLS, output XLS. If you output HTML, name it .HTML. – Brad Sep 13 '11 at 15:00
  • @Brad Because i don't have available time to implement a class that generates and outputs and .xls, only because of that. (As in "the deadline is in 10 hours and i'm way behind getting things done, we're a team of 3 pulling an all nighter at this very moment.) – Jorge Guberte Sep 14 '11 at 03:45