Force download excel file not working on web server

0 votes

The following coding works on localhost perfectly for force to download an excel file but doesn't work on a web server.

$par_name="worker_report";
$nwdatetime=date('d-m-Y h-i-s');
$fi = $par_name."_". $nwdatetime;
$extns=".xls";
header('Content-Type: application/force-download');  
header('Content-disposition: attachment; filename='.$fi.$extns);  

header("Pragma: ");  
header("Cache-Control: ");  
$_REQUEST['datatodisplay'];  
Oct 11, 2022 in Others by Kithuzzz
• 38,010 points
1,801 views

1 answer to this question.

0 votes

Change the content type to Content-Type: application/vnd.ms-excel

Or try this code if works.

$par_name="worker_report";
$nwdatetime=date('d-m-Y h-i-s');
$fi = $par_name."_". $nwdatetime;
$extns=".xls";

// Redirect output to a client’s web browser (Excel5)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename='.$fi.$extns);
    header('Cache-Control: max-age=0');

    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');

    // If you're serving to IE over SSL, then the following may be needed
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header ('Pragma: public'); // HTTP/1.0

    $_REQUEST['datatodisplay']; 
answered Oct 11, 2022 by narikkadan
• 63,420 points

Related Questions In Others

0 votes
1 answer

Excel MATCH function is not working on an array but works once directed to the matched value

According to the definition here: support.microsoft.com/en-us/office/… if you do ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,420 points
656 views
0 votes
1 answer

How to deploy flutter web on server?

Hi@akhtar, To create a production build for the ...READ MORE

answered Sep 15, 2020 in Others by MD
• 95,440 points
2,815 views
0 votes
0 answers

PhpMyAdmin not working on localhost

I had recently installed the Xampp version:1.7.7 ...READ MORE

Feb 8, 2022 in Others by Soham
• 9,700 points
1,304 views
0 votes
1 answer

PhpMyAdmin not working on localhost

In order to answer your question, you ...READ MORE

answered Feb 8, 2022 in Others by Rahul
• 9,670 points
4,845 views
0 votes
1 answer

How to upload excel file to php server from <input type="file">

You first need to upload the file ...READ MORE

answered Jun 9, 2022 in JQuery by gaurav
• 23,260 points
6,040 views
0 votes
0 answers

PHP import Excel into database (xls & xlsx)

One of the plugins I looked for ...READ MORE

Jul 30, 2022 in PHP by Kithuzzz
• 38,010 points
1,187 views
0 votes
1 answer

Online Excel Web-based Platform

You can use any of the following ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 63,420 points
328 views
0 votes
1 answer

Codeigniter convert excel file to pdf

This is a basic php script for ...READ MORE

answered Sep 27, 2022 in Others by narikkadan
• 63,420 points
1,098 views
0 votes
1 answer
0 votes
1 answer

Download file from URL in Excel 2019 (it works on Excel 2007)

The Sub Code looks fine. Check the ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 63,420 points
1,383 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP