2016-06-20 5 views
0

Ich habe eine Schaltfläche "Excel-Datei herunterladen" auf meiner Website. Wenn ich auf diese Schaltfläche klicke, wird download_header() Funktion ausgeführt. Hier ist der Code der FunktionExport Excel-Datei mit PHPExcel funktioniert in meinem lokalen PC, aber nicht im Live-Server

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'); 
} 

Und hier ist die table_field_name() Funktion des Code

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

Es funktioniert gut in meinem localhost und ich kann Datei herunterladen Excel aber nicht in Live-Server zu arbeiten. es zeigt diesen Fehler

Diese Seite nicht Die Webseite unter http://dataraceltd.com/demo/bin/download_excel_file/download_header/18 erreicht werden kann, ist möglicherweise vorübergehend oder dauerhaft an eine neue Webadresse verschoben haben. ERR_INVALID_RESPONSE

Plz Hilfe

Antwort

1

Seine scheint Ihnen die Erlaubnis bezogenes Problem auf dem Server. Bitte überprüfen Sie zuerst die Schreibrechte auf dem Server.

+1

Dies funktioniert in PHP Version 5.4, aber nicht in PHP Version 7 –

+1

Dies war ein PHP und PHPEXCEL Version Problem. Jetzt funktioniert das mit phplexcel 1.8.1. phpexcel 1.8.0 funktioniert nicht in php7, aber funktioniert weniger als php7 version. –