check the all tags are closed ( opening and closing). Remove all blank lines from php page.
Force download without losing the format?
-
30-06-2023 - |
Question
I want to download text file from server to client, the code is working but after I download the text file it shows an extra blank line at top.
How do I remove that line or how do I get the original format of the text file into the client machine?
Here is my code:
$code = $_POST["Code"];
$File = "my$code.txt";
if (file_exists($File))
{
header("Content-Type:text/plain");
header ("Content-Disposition: attachment; filename=$File");
header("Content-Length:" . filesize("$File"));
$fp = fopen("$File", "r");
fpassthru($fp);
}
Solution 2
OTHER TIPS
Make sure there is nothing in front of the opening <?php tag.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow