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");
5
  • 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 5, 2014 at 9:39
  • try header('Content-type: application/ms-excel'); Jan 5, 2014 at 9:46
  • This has been asked a thousand times before, please use the search.
    – hakre
    Jan 5, 2014 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 5, 2014 at 10:36
  • Thank you for your responses.I added ob_start() before the session_start() and it worked for me
    – praveen
    Jan 6, 2014 at 11:28

1 Answer 1

1

these headers will work beter

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.