Reputation: 39
I have problem with my PHP code:
header('Content-Disposition: attachment; filename="config.yml"');
header('Content-Type: text/plain');
header('Content-Length: '.strlen($file));
readfile($file);
File is downloaded well, but page will close instantly. Like downloading will start, and page will close. But I have in page also some else code, like html. I don't want to close page after downloading. Can you give me some advice ? Because I don't know, where can be mistake.
Upvotes: 3
Views: 92
Reputation: 9343
You cannot return both the file download and html or other content in the same response.
What you need to do is return the html first and within that have a request for the download. E.g.
<iframe width="1" height="1" frameborder="0" src="/downloadfile.php"></iframe>
Upvotes: 1