下载

示例

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('Content-Length: ' . filesize($filePath));
31
header('Content-Transfer-Encoding: binary');
32
header('Cache-Control: must-revalidate');
33
header('Cache-Control: max-age=0');
34
header('Pragma: public');
35
36
ob_clean();
37
flush();
38
39
if (copy($filePath, 'php://output') === false) {
40
// Throw exception
41
}
42
43
// Delete temporary file
44
@unlink($filePath);
Copied!
Last modified 1yr ago
Copy link