Unable to create excel file on server

I am new to PHP. I want to create an excel file. I tried the code below.

<?php
    $loc= getcwd();
    require_once "Classes/PHPExcel/IOFactory.php";

    $objTpl = new PHPExcel();
    $objTpl->setActiveSheetIndex(0); 
    $objTpl->getActiveSheet()->setCellValue('A1', 'URL');
    $objTpl->getActiveSheet()->setCellValue('B1', 'No of post');
    $j=2;
if (!ini_get('safe_mode'))
{
    set_time_limit(0);
}
ini_set('memory_limit', '2700M');
error_reporting(0);
header('Content-Type:text/html; charset=UTF-8');

$filepath = 'csv/sample.csv';
require_once './File_CSV_DataSource.php';
include_once('simple_html_dom.php');

$csv = new File_CSV_DataSource;

 //$date=getdate();
 $objTpl->getActiveSheet()->getColumnDimension('A')->setWidth(40);
 $objTpl->getActiveSheet()->getColumnDimension('B')->setWidth(15);
 $objWriter = new PHPExcel_Writer_Excel2007($objTpl);

 echo $loc;
 $date = date('Y-m-d');
 $objWriter->save($loc.'/result/'.$date.'.xlsx');
    $objTpl->disconnectWorksheets();
    unset($objWriter, $objTpl);      ?>

The code works fine on my local computer, but not on my server. Why doesn't it work?

+3
source share
1 answer

A prerequisite for PHPExcel is the inclusion of the ZipArchive class if you want to work with files compressed using zip, such as xlsx or ods files.

If you do not have ZipArchive installed, PHPExcel has a built-in alternative using PCLZip, although it is slower and more hungry. It is disabled by default because ZipArchive is the preferred method and should be available in most versions of PHP; but you can enable it using

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);

before reading or saving any zip-based file

+1
source

All Articles