我有一个文档下载站点,可以在其中跟踪下载的文件。
我的问题是通过我正在使用的脚本下载 zip 文件。除 zip 文件外,所有其他文件都被迫下载。当一个 zip 文件被推送时,它只是转到脚本所在的 download.php 页面,没有文件被推送出去。
ob_start();
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;