简体   繁体   中英

PHP headers not working on server but works on local server?

header("Content-type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=filename.xls");
header("Pragma: no-cache");
header("Expires: 0");

On my local system above code work properly but on server its not work.

I don't know yet if it will help you, but if you wan't, you can generalize octet-stream output for some extension, directly in VirtualHost config.

For that, use AddType application/octet-stream .xlsx .xls

And all url to Excel files would be downloaded.

write ob_clean() just before the last line below , i was having same problem got resolved by this

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="temlik.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_clean();
$objWriter->save('php://output');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM