0

I have written a PHP script for exporting results to the Excel sheet and it works fine in the local machine.

But when i upload my script to the live server it prints the records in an Page (like HTML Output) instead of exporting those results to the excel sheet.I have installed XAMPP server in the live environment.

Please tell me whether I need change any settings in the PHP.ini file or some where else to make export work.

I have used the following headers in my code

header("Content-type: application/vnd.ms-excel; name='excel'");
header("Content-Disposition: attachment; filename=exportfile.xls");
header("Pragma: no-cache");
header("Expires: 0");
hakre
  • 193,403
  • 52
  • 435
  • 836
praveen
  • 286
  • 1
  • 8
  • does the preceding code maybe give a warning or error? that would result in the headers not being sent. check the headers with a debugging tool! the headers should work fine as far as i can tell – x4rf41 Jan 05 '14 at 09:39
  • try header('Content-type: application/ms-excel'); – Simone Nigro Jan 05 '14 at 09:46
  • This has been asked a thousand times before, please use the search. – hakre Jan 05 '14 at 10:21
  • It is also important that you enable error reporting and logging to the highest level and check for notices, warnings and errors. – hakre Jan 05 '14 at 10:36
  • Thank you for your responses.I added ob_start() before the session_start() and it worked for me – praveen Jan 06 '14 at 11:28

1 Answers1

1

these headers will work beter

    header("Content-Description: File Transfer;");
    header("Content-Type: application/force-download;");
  • Thank you for your responses.I added ob_start() before the session_start() and it worked for me – praveen Jan 06 '14 at 11:29