Blank lines in top of file downloaded via PHP

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.

Advertisements


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s