2015-09-13 33 views
3

我有问题,我的PHP代码:PHP文件下载与头

header('Content-Disposition: attachment; filename="config.yml"'); 
header('Content-Type: text/plain'); 
header('Content-Length: '.strlen($file)); 
readfile($file); 

文件下载好,但页面会立即关闭。 像下载将开始,页面将关闭。但是我在页面中也有一些其他代码,比如html。 下载后我不想关闭页面。 你能给我一些建议吗?因为我不知道,哪里会出错。

回答

1

您不能在同一个响应中返回文件下载和html或其他内容。

你需要做的是先返回html,并在那里有一个下载请求。例如。

<iframe width="1" height="1" frameborder="0" src="/downloadfile.php"></iframe>