Download

Example

1
function getTmpDir(): string
2
{
3
$tmp = ini_get('upload_tmp_dir');
4
5
if ($tmp !== False && file_exists($tmp)) {
6
return realpath($tmp);
7
}
8
9
return realpath(sys_get_temp_dir());
10
}
11
12
$config = [
13
'path' => getTmpDir() . '/',
14
];
15
16
$fileName = 'tutorial01.xlsx';
17
$xlsxObject = new \Vtiful\Kernel\Excel($config);
18
19
// Init File
20
$fileObject = $xlsxObject->fileName($fileName);
21
22
// Writing data to a file ......
23
24
// Outptu
25
$filePath = $fileObject->output();
26
27
// Set Header
28
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
29
header('Content-Disposition: attachment;filename="' . $fileName . '"');
30
header('Cache-Control: max-age=0');
31
32
if (copy($filePath, 'php://output') === false) {
33
// Throw exception
34
}
35
36
// Delete temporary file
37
@unlink($filePath);
Copied!
Last modified 2yr ago
Copy link