Blank lines in top of file downloaded via PHPPosted: February 22, 2017
You are serving a file for download directly from your PHP script, by setting its mime type, sending headers with Content-Type and Content-Disposition, then piping the contents.
Everything works fine, but then suddenly the downloads become corrupted, with extra data added in their top, with blank extra lines clearly visible in downloaded text files.
The first thing to do without thinking much is to go through your PHP files and remove closing “?>“, if they are at the very end of the file. They are not needed and actually can be harmful, as anything after “?>” may served to the user with potentially damaging results.
Just remove those “?>” and your downloads may be fine again.