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 in Others by Kithuzzz
• 20,660 points
91 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 by narikkadan
• 37,660 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 in Others by narikkadan
• 37,660 points
29 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,380 points
2,352 views
0 votes
0 answers

PhpMyAdmin not working on localhost

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

Feb 8 in Others by Soham
• 9,670 points
57 views
0 votes
1 answer

PhpMyAdmin not working on localhost

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

answered Feb 8 in Others by Rahul
• 9,680 points
1,247 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 in JQuery by gaurav
• 22,040 points
1,977 views
0 votes
0 answers

PHP import Excel into database (xls & xlsx)

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

Jul 30 in PHP by Kithuzzz
• 20,660 points
400 views
0 votes
1 answer

Online Excel Web-based Platform

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

answered Sep 24 in Others by narikkadan
• 37,660 points
47 views
0 votes
1 answer

Codeigniter convert excel file to pdf

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

answered Sep 27 in Others by narikkadan
• 37,660 points
187 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 in Others by narikkadan
• 37,660 points
132 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