使用在我的本地PC中工作的PHPExcel导出Excel文件,但在实时服务器中工作的Excel文件 [英] Export excel file using PHPExcel working in my local pc but not working in live server

查看:73
本文介绍了使用在我的本地PC中工作的PHPExcel导出Excel文件,但在实时服务器中工作的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个下载excel文件"按钮.当我单击此按钮时,它将运行download_header()功能.这是函数的代码

I have a "Download excel file" button in my website. When I click this button, it runs download_header() function. Here is the function's code

public function download_header($pid)
{
    // get pick_list table's field name
    $this->load->model('Download_excel_model');
    $fields = $this->Download_excel_model->table_field_name('pick_list');

    // Starting the PHPExcel library
    $this->load->library('excel');
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setTitle("export")->setDescription("none");
    $objPHPExcel->setActiveSheetIndex(0);
    // Field names in the first row
    $col = 0;
    foreach ($fields as $field)
    {
        if($field != 'id' && $field != 'status' && $field != 'created_date' && $field != 'updated_date' && $field != 'extra' && $field != 'user_id' && $field != 'pid' && $field != 'qty_scaned')
        {
            $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field);
            $col++;
        }
    }

    $objPHPExcel->setActiveSheetIndex(0);
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    // Sending headers to force the user to download the file
    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    header('Content-Disposition: attachment;filename="Sample_'.date('dMy').'.xlsx"');
    header('Cache-Control: max-age=0');
    $objWriter->save('php://output');
}

这是table_field_name()函数的代码

public function table_field_name($table)
{
    $query = $this->db->list_fields($table);
    return $query;
}

在我的本地主机上工作正常,我可以下载excel文件,但不能在实时服务器上运行.它显示此错误

It's working fine in my localhost and I can download excel file but not working it in live server. it shows this error

无法访问此网站 该网页位于 http://dataraceltd.com/demo/bin/download_excel_file/download_header/18 可能暂时关闭,或者已永久移动到新的网址. ERR_INVALID_RESPONSE

This site can’t be reached The webpage at http://dataraceltd.com/demo/bin/download_excel_file/download_header/18 might be temporarily down or it may have moved permanently to a new web address. ERR_INVALID_RESPONSE

Plz帮助

推荐答案

似乎您在服务器上有权限相关的问题.请首先检查服务器上的写权限.

Its seems you have permission related issue on the server. Please first check the write permission on the server.

这篇关于使用在我的本地PC中工作的PHPExcel导出Excel文件,但在实时服务器中工作的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆