I have a function named get_reports()
(that downloads an excel file) within a Controller named Bulkexport
Navigating to the URL http://localhost/mycontroller/bulkexport/get_reports
downloads an excel file.
I have the same code on the server but instead of downloading it navigates to https://example.com/mycontroller/bulkexport/get_reports
and the browser throws the following error:
This site can’t be reached The webpage at https://www.example.com/mycontroller/bulkexport/get_reports might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE"
This worked previously on a different server. Once I changed to a different server it is not working.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class Bulkexport extends Mycontroller_Controller {
............
.......
public function get_reports(){
$id = $this->ion_auth->user()->row()->id;
.............
..........
....
$spreadsheet->getActiveSheet()->setTitle('batches');
$spreadsheet->setActiveSheetIndex(0);
/*---------------------------------------------------creating file-----------------------------------*/
$writer = new Xlsx($spreadsheet);
$filename = 'Reports';
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="'. $filename .'.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output'); // download file
}
}