blank line at beginning of downloaded file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m. verkerk

    blank line at beginning of downloaded file

    Hi everybody!

    Hope someone can help me out with this!

    I'm sending a file to a user with the following code:

    header( "Content-Type: application/binary");
    header( "Content-disposition: attachment; filename=$filen ame");
    header( "Content-Transfer-Encoding: binary" );
    passthru( "svnadmin dump ".$svn_repos_lo c."/".$name );

    (the svnadmin dump command returns a mostly ascii file, but could also
    contain some non-ascii parts)

    Somehow the file that is saved on the recipients computer gets an
    additional blank first line. Off course I can strip this somehow, but
    I'm interested in an explanation of this behavior and I would like a
    more appropriate solution!

    Thanks & regards,
    Marijn
  • Peter Fox

    #2
    Re: blank line at beginning of downloaded file

    Following on from m. verkerk's message. . .[color=blue]
    >Hi everybody!
    >
    >Hope someone can help me out with this!
    >
    >I'm sending a file to a user with the following code:
    >
    >header( "Content-Type: application/binary");
    >header( "Content-disposition: attachment; filename=$filen ame");
    >header( "Content-Transfer-Encoding: binary" );
    >passthru( "svnadmin dump ".$svn_repos_lo c."/".$name );
    >
    >(the svnadmin dump command returns a mostly ascii file, but could also
    >contain some non-ascii parts)
    >
    >Somehow the file that is saved on the recipients computer gets an
    >additional blank first line. Off course I can strip this somehow, but
    >I'm interested in an explanation of this behavior and I would like a
    >more appropriate solution![/color]

    CR <> CRLF <> LF problem?
    The HTTP protocol (rfc2616) uses new lines /blank lines at the end of a
    header and it hasa away of interpreting CR/LF etc.




    --
    PETER FOX Not the same since the poster business went to the wall
    peterfox@eminen t.demon.co.uk.n ot.this.bit.no. html
    2 Tees Close, Witham, Essex.
    Gravity beer in Essex <http://www.eminent.dem on.co.uk>

    Comment

    • Brion Vibber

      #3
      Re: blank line at beginning of downloaded file

      m. verkerk wrote:[color=blue]
      > Somehow the file that is saved on the recipients computer gets an
      > additional blank first line. Off course I can strip this somehow, but
      > I'm interested in an explanation of this behavior and I would like a
      > more appropriate solution![/color]

      Check for extra whitespace before the <? or after the ?> in your PHP
      source files. Remember to check any include()s...

      -- brion vibber (brion @ pobox.com)

      Comment

      • Malcolm Dew-Jones

        #4
        Re: blank line at beginning of downloaded file

        Brion Vibber (brion@pobox.co m) wrote:
        : m. verkerk wrote:
        : > Somehow the file that is saved on the recipients computer gets an
        : > additional blank first line. Off course I can strip this somehow, but
        : > I'm interested in an explanation of this behavior and I would like a
        : > more appropriate solution!

        : Check for extra whitespace before the <? or after the ?> in your PHP
        : source files. Remember to check any include()s...

        Note especially that it may be your editor inserting a final new line at
        the very end of the php source file.

        The > character in the final ?> must be the very last character in the
        file.

        On unix type "od -c file" to examine the bytes in the file. The last
        bytes will be at the end (right?) so it doesn't matter if the file scrolls
        by - you only need to see the last byte.

        On windows, when all else fails, the lowly notepad can be used to find and
        remove a trailing line break in a text file.

        --

        This space not for rent.

        Comment

        • Brion Vibber

          #5
          Re: blank line at beginning of downloaded file

          Malcolm Dew-Jones wrote:[color=blue]
          > Note especially that it may be your editor inserting a final new line at
          > the very end of the php source file.
          >
          > The > character in the final ?> must be the very last character in the
          > file.[/color]

          Actually, a single final newline after the ?> is ok. But if you have a
          space *and* a final newline, or *two* final newlines, they will be output.

          (At least this is the case on Unix; if you have Windows-style CRs in
          there, who knows what dreadful things happen...)

          -- brion vibber (brion @ pobox.com)

          Comment

          • Chung Leong

            #6
            Re: blank line at beginning of downloaded file

            "Malcolm Dew-Jones" <yf110@vtn1.vic toria.tc.ca> wrote in message
            news:42377365@n ews.victoria.tc .ca...[color=blue]
            > Brion Vibber (brion@pobox.co m) wrote:
            > : m. verkerk wrote:
            > : > Somehow the file that is saved on the recipients computer gets an
            > : > additional blank first line. Off course I can strip this somehow, but
            > : > I'm interested in an explanation of this behavior and I would like a
            > : > more appropriate solution!
            >
            > : Check for extra whitespace before the <? or after the ?> in your PHP
            > : source files. Remember to check any include()s...
            >
            > Note especially that it may be your editor inserting a final new line at
            > the very end of the php source file.
            >
            > The > character in the final ?> must be the very last character in the
            > file.[/color]

            Actually, PHP will swallow one linefeed right after ?> or </script>.


            Comment

            • Tim Roberts

              #7
              Re: blank line at beginning of downloaded file

              "m. verkerk" <m.verkerk@eras musmc.nl> wrote:
              [color=blue]
              >Hi everybody!
              >
              >Hope someone can help me out with this!
              >
              >I'm sending a file to a user with the following code:
              >
              >header( "Content-Type: application/binary");[/color]

              I doubt this is related to your problem, but the RFC1521-approved content
              type for binary data is "applicatio n/octet-stream". "Applicatio n/binary"
              is not defined, as far as I know.
              --
              - Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.

              Comment

              • m. verkerk

                #8
                Re: blank line at beginning of downloaded file

                Thank you all for the help!

                After closer examination, this white line seems to be caused by the
                application framework I'm using (Prado).

                thanks again!

                Marijn

                m. verkerk wrote:[color=blue]
                > Hi everybody!
                >
                > Hope someone can help me out with this!
                >
                > I'm sending a file to a user with the following code:
                >
                > header( "Content-Type: application/binary");
                > header( "Content-disposition: attachment; filename=$filen ame");
                > header( "Content-Transfer-Encoding: binary" );
                > passthru( "svnadmin dump ".$svn_repos_lo c."/".$name );
                >
                > (the svnadmin dump command returns a mostly ascii file, but could also
                > contain some non-ascii parts)
                >
                > Somehow the file that is saved on the recipients computer gets an
                > additional blank first line. Off course I can strip this somehow, but
                > I'm interested in an explanation of this behavior and I would like a
                > more appropriate solution!
                >
                > Thanks & regards,
                > Marijn[/color]

                Comment

                • John Dunlop

                  #9
                  Re: blank line at beginning of downloaded file

                  Tim Roberts wrote:
                  [color=blue]
                  > but the RFC1521-approved content type for binary data is
                  > "applicatio n/octet-stream".[/color]

                  Yes, arbitrary binary data.
                  [color=blue]
                  > "Applicatio n/binary" is not defined, as far as I know.[/color]

                  It isn't defined publicly; that is, it isn't registered
                  with the IANA. So the subtype should be prefixed with 'x-',
                  giving 'application/x-binary'.

                  But as you say, 'octet-stream' is the registered subtype.

                  --
                  Jock

                  Comment

                  Working...