Problem using fpassthru()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leslie Houk

    Problem using fpassthru()

    I'm just learning PHP, and I'm having a problem using fpassthru(). I
    want to download a file using the following code segment I found,
    which I put into my testing file called portal.php:

    $fileString = './' . $params[1];
    // translate file name properly for Internet Explorer.
    if ( strstr( $_SERVER['HTTP_USER_AGEN T'], "MSIE" )) {
    $params[1] = preg_replace( '/\./', '%2e', $params[1],
    substr_count($p arams[1], '.') - 1 );
    }
    header( "Cache-Control: " ); // leave blank for IE
    header( "Pragma: " ); // leave blank for IE
    header( "Content-type: application/octet-stream" );
    header( "Content-Disposition: attachment; filename=\"" .
    $params[1] . "\"" );
    header( "Content-length:" . (string)(filesi ze( $fileString )));
    sleep(1);
    $fdl = @fopen( $fileString, 'rb' );
    fpassthru( $fdl );

    However, when I run it, I get the following:

    Warning: Cannot modify header information - headers already sent
    by (output started at /export/home/.../portal.php:26) in
    /export/home/.../portal.php on line 178

    Warning: Cannot modify header information - headers already sent
    by (output started at /export/home/.../portal.php:26) in
    /export/home/.../portal.php on line 179

    Warning: Cannot modify header information - headers already sent
    by (output started at /export/home/.../portal.php:26) in
    /export/home/.../portal.php on line 180

    Warning: Cannot modify header information - headers already sent
    by (output started at /export/home/.../portal.php:26) in
    /export/home/.../portal.php on line 182

    Warning: Cannot modify header information - headers already sent
    by (output started at /export/home/.../portal.php:26) in
    /export/home/.../portal.php on line 183

    The contents of the file I am trying to download (an html file) is
    then displayed, interpreted as if it were appended to the end of
    portal.php. Does anyone know what is causing this, and how I can fix
    it? Thanks in advance to all who respond.
  • Filth

    #2
    Re: Problem using fpassthru()

    > Warning: Cannot modify header information - headers already sent[color=blue]
    > by (output started at /export/home/.../portal.php:26) in
    > /export/home/.../portal.php on line 178
    >
    > Warning: Cannot modify header information - headers already sent
    > by (output started at /export/home/.../portal.php:26) in
    > /export/home/.../portal.php on line 179
    >
    > Warning: Cannot modify header information - headers already sent
    > by (output started at /export/home/.../portal.php:26) in
    > /export/home/.../portal.php on line 180
    >
    > Warning: Cannot modify header information - headers already sent
    > by (output started at /export/home/.../portal.php:26) in
    > /export/home/.../portal.php on line 182
    >
    > Warning: Cannot modify header information - headers already sent
    > by (output started at /export/home/.../portal.php:26) in
    > /export/home/.../portal.php on line 183[/color]

    these are ussually caused when you have already output data to the browser,
    if any output has been sent (even a single space) then headers can not be
    sent


    Comment

    • Leslie Houk

      #3
      Re: Problem using fpassthru()

      "Filth" <peter@petermcd onald.co.uk> wrote in message news:<ynjGc.361 $sw4.5393452@ne ws-text.cableinet. net>...[color=blue]
      >
      > these are usually caused when you have already output data to the browser,
      > if any output has been sent (even a single space) then headers can not be
      > sent[/color]

      Thanks for your response. Now, am I using the wrong technique to download
      a file from a host server? Is there a better way, or am I just using the
      correct technique incorrectly? I would appreciate some guidance, since
      PHP in general is still new to me.

      Comment

      • Andy Barfield

        #4
        Re: Problem using fpassthru()

        Leslie Houk wrote:[color=blue]
        > Does anyone know what is causing this, and how I can fix
        > it? Thanks in advance to all who respond.[/color]

        You need to use output buffering. Check the manual at
        http://www.php.net/ob_start for somewhere to start.

        Regards,

        Andy

        Comment

        • Leslie Houk

          #5
          Re: Problem using fpassthru()

          Andy Barfield <abarfield_01@y ahoo.com> wrote in message news:<k6mdnXaa2 5Z_XHfdRVn-hQ@nildram.net> ...[color=blue]
          > Leslie Houk wrote:[color=green]
          > > Does anyone know what is causing this, and how I can fix
          > > it? Thanks in advance to all who respond.[/color]
          >
          > You need to use output buffering. Check the manual at
          > http://www.php.net/ob_start for somewhere to start.
          >
          > Regards,
          >
          > Andy[/color]

          Andy,

          Thanks for the link! The last user comment on that page pointed
          me to "http://www.devshed.com/c/a/PHP/Output-Buffering-With-PHP/",
          which told me exactly how to do what I need.

          Leslie

          Comment

          Working...