Skip to content

Commit

Permalink
ob_end_clean should be called BEFORE headers are sent
Browse files Browse the repository at this point in the history
Follow-up to commit b341ca8

ob_end_clean throws away the output buffer instead of flushing it to the
client. Therefore we should call this BEFORE the file download headers
are sent to the client or else these headers could potentially be thrown
away/lost.

Note to self: don't rely upon incorrect comments in the code that tell
you ob_end_clean flushes the buffer... look it up in the PHP manual!
  • Loading branch information
davidhicks committed Oct 28, 2009
1 parent c8a9d4a commit be57bb8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions file_download.php
Expand Up @@ -84,6 +84,9 @@
break;
}

# throw away output buffer contents (and disable it) to protect download
while ( @ob_end_clean() );

if ( ini_get( 'zlib.output_compression' ) && function_exists( 'ini_set' ) ) {
ini_set( 'zlib.output_compression', false );
}
Expand Down Expand Up @@ -152,8 +155,6 @@
}

header( 'Content-Type: ' . $t_content_type );
# flush output buffer (and disable it) to protect download
while ( @ob_end_clean() );
file_send_chunk( $t_local_disk_file );
}
break;
Expand All @@ -175,8 +176,6 @@
}

header( 'Content-Type: ' . $t_content_type );
# flush output buffer (and disable it) to protect download
while ( @ob_end_clean() );
readfile( $t_local_disk_file );
break;
default:
Expand All @@ -189,8 +188,6 @@
}

header( 'Content-Type: ' . $t_content_type );
# flush output buffer (and disable it) to protect download
while ( @ob_end_clean() );
echo $v_content;
}
exit();
Expand Down

0 comments on commit be57bb8

Please sign in to comment.