Change path to save a file created with PHPExcel

0

I use the PHPExcel library to create an excel file with data from a DB, the problem is that it saves the excel generated in the server path where the php file that generated it is, the following code is a fragment of what I use, I would like to be able to choose the download path for that file.

$objPHPExcel->getActiveSheet()->setTitle('Simple');

$objPHPExcel->setActiveSheetIndex(0);

$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save(str_replace('.php', '.xls', __FILE__));
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;
    
asked by Rafa FE 10.05.2017 в 00:52
source

1 answer

0

You have to put the path in the save method:

Relative path:

$objWriter->save('../../files/archivo.xls');

Absolute route

$objWriter->save('/var/www/files/archivo.xls');
    
answered by 10.05.2017 / 03:13
source