PHP include函数将解析文件.你想要做的是使用file_get_contents或readfile.
这是readfile文档中的一个示例:
$file = 'somefile.gif';
if (file_exists($file)) {
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;
}
Run Code Online (Sandbox Code Playgroud)
更改标题以满足您的特定需求.查看以上链接以获取更多信息.