douhuan1257 2019-07-30 05:53
浏览 65

CodeIgniter控制器中的函数(download_report())正在本地计算机上运行,​​但不在服务器上运行

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 
    }
}
  • 写回答

1条回答 默认 最新

  • doulan4939 2019-07-30 06:22
    关注

    Make sure these extensions are installed in server (php_gd2, php_xml and php_zip)

    sudo apt-get install php-zip
    sudo apt-get install php-gd
    sudo apt-get install php-xml
    

    This will install latest version. You can can configure it depend on your PHP version.

    For examaple sudo apt-get install php5.6-gd (If your php version is 5.6)

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端