Change saving directory in phpspreadsheet

Javier Rincon picture Javier Rincon · Jun 5, 2018 · Viewed 7.6k times · Source

Im using PhpSpreadsheet to generate XLS files, all the functions work perfect except that it saves local files in temporary directories and I want to save them in a specific folder.

use PhpOffice\PhpSpreadsheet\IOFactory;
require __DIR__ . '/Header.php';

$spreadsheet = require __DIR__ . '/templates/MyTemplate.php';

$filename = $helper->getFilename("MyFilename", 'xls'); 
$writer = IOFactory::createWriter($spreadsheet, 'Xls');

$callStartTime = microtime(true);
$writer->save($filename);
$helper->logWrite($writer, $filename, $callStartTime);

But the output is located in

Write Xls format to /var/folders/pn/lyj970q90lq20mjv39bpgx_80000gn/T/phpspreadsheet/MyFilename.xls in 0.0640 seconds

Is there an other function to set the saving directory I want the files in?

Answer

YurgenTM picture YurgenTM · Aug 22, 2018

Use dot in path

$writer->save("./templates/MyFilename.xls");