0

I have a file download function in my website. it works fine before. but after we moved the site to another server with runs PHP 5 (it runs on PHP 4 before). when click to download, it automatically adds a extra blank line at the beginning and the end of the file which we don't want to. Here is the code for downloading function:

header("Content-Type: application/gas");
header("Cache-control: private");    
header("Content-Disposition: attachment; filename=aaa.gas");

Could anyone please help me out? Thanks!

3
  • perhaps printing file content instead of Content-Disposition header would help? Commented Jan 14, 2011 at 14:37
  • Off topic: The RFC 2231 standard states you should surround your filename in double quotes. If you were to try and provide a filename that has a space in it, the download will not play nice in Firefox. kb.mozillazine.org/… Commented Jan 14, 2011 at 14:38
  • 2
    The given code doesn't actually print the output, nor does it show the PHP open/close tags. It's clear that this question is missing a pertinent testcase, and without one it cannot be answered. Commented Jan 14, 2011 at 14:39

1 Answer 1

4

There may be an extra blank line after the ?> that closes the PHP within the script. Exit the script after sending the file in order to prevent this from mattering.

Sign up to request clarification or add additional context in comments.

7 Comments

Or simply don't close your PHP tag. There's usually no need to.
For the love of God, please always close your PHP tags. That's a bad habit to get into.
This comment of mine is redundant, but it's so VERY important, so here we go: @MichaelIrigoyen must be listened to here!
@Tomalak. If a file contains only PHP, and is not a HTML template, it should open with <?php and have no closing tag. There's no call for one. All it does is introduce the possibility of this error.
@TRiG: And look horrible. I guess I can't really come up with any practical downside to it, which is frustrating, but I heavily disagree with getting into this habit. It just seems messy and dangerous somehow.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.