Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change saving directory in phpspreadsheet

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?

like image 594
Javier Rincon Avatar asked Oct 16 '25 04:10

Javier Rincon


1 Answers

Use dot in path

$writer->save("./templates/MyFilename.xls");
like image 112
YurgenTM Avatar answered Oct 17 '25 21:10

YurgenTM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!