Unable To Save File Generated By Yiiexcel On Webhosting

Hy!

Let me introduce my problem: I want to export some data from database to excel, but after generating the file with operator new PHPExcel_Writer_Excel2007($xls) I get only a blank page and no file appears for download. The code perpectly works on localhost, not as so on webhosting. The code is:


public function actionExcel()

  {

    $filename = date('Y_m_d_H_i_s').'file.xlsx';

    

    $xls = new PHPExcel();

    $xls->getProperties()->setCreator("szotyesz");

    $xls->getProperties()->setLastModifiedBy("szotyesz");

    $xls->getProperties()->setTitle("Test");

    $xls->getProperties()->setSubject("Test");

    $xls->getProperties()->setDescription("Test");

    

    $model=new Order('search');

    $model->unsetAttributes();  // clear any default values

    

    $dataProvider = $model->search(false);

    $result = array(Order::model()->getAttributeLabel("id"), 

            Order::model()->getAttributeLabel("type"), 

            Order::model()->getAttributeLabel("item"),

            Order::model()->getAttributeLabel("description"),

            Order::model()->getAttributeLabel("price"),

            Order::model()->getAttributeLabel("create_time"), 

            Order::model()->getAttributeLabel("create_user_id"), 

            Order::model()->getAttributeLabel("status_id"),

            Order::model()->getAttributeLabel("agree_purpose"),

            Order::model()->getAttributeLabel("agreed_by"),

            Order::model()->getAttributeLabel("agree_time"));

    

    // data

    foreach ($dataProvider->getData() as $data) {

      array_push($result, array($data->id, $data->type, $data->item, $data->description, $data->price, $data->create_time, $data->create_user_id, $data->status_id, $data->agree_purpose, $data->agreed_by, $data->agree_time));

    }

    

    $xls->getActiveSheet()->fromArray($result, NULL, 'A1');

    

    // Redirect output to a client’s web browser

    header('Content-Type: application/vnd.ms-excel');

    header('Content-Disposition: attachment;filename="'.$filename.'"');

    header('Cache-Control: max-age=0');

    

    $objWriter = new PHPExcel_Writer_Excel2007($xls);

    $objWriter->save('php://output');

    exit;

}

I could save file from webhosting when to save method I have passed $filename, but in the generated file was empty. The other wierd became, when I was sending out some info with echo, these infos were saved into the genereted file. I have no idea why it doesn`t work. PHP on server is 5.2.14.

If you have any idea that could solve this problem, please let me know.

Thanks in advance.

You should check the log file. If you use Apache as your web server, check on error.log file. It might mention something related to incorrect content of the PHP file.

There is another wrapper you can use to create Excel file, tlbExcelView.

Thank You for reply, I solved it temporary without extension (directly with headers and echo-s) while it don`t will go with extension. I think there will be something with Yii framework default path to TEMP dir, because not in Yii webapp dir phpExcel works fine. Same issue appears with other extension like mPdf.

directory structure:

/temp

/yii_framework

/www_root/dir/webapp