From:             mmosel at gmail dot com
Operating system: Unix and Win2k
PHP version:      4.4.2
PHP Bug Type:     Output Control
Bug description:  forced download error - using output buffer, content-length 
header & readfile

Description:
------------
Here's the bug. If someone wants to deliver a forced file download, in
this case a zip file, and if they use php's output buffer along with the
header("Content-length:"), readfile() - if there is any other content
output in the output buffer, the file will download but it will not open
because of an error with the length. If you remove the length line, the
file will download, but the browser doesn't know how big the file is,
which is bad for the user. The included code will illustrate this error.
If you remove the echo message, the file will download without error.

Reproduce code:
---------------
<?php
ob_start();
echo 'message here';

$source = '../pathtofile/file.zip';

$pr_file_name ='downloadtest.zip';
$length = filesize($source);
     header('Pragma: private');
     header('Cache-control: private, must-revalidate');
     header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");     
     
     header("Content-type: application/zip");
     header("Content-Transfer-Encoding: Binary");
     header("Accept-Ranges: bytes");
     header("Content-length: $length");
    
     header("Content-disposition: attachment;
     filename=".$pr_file_name);    
     
     
     readfile($source);
ob_end_flush();
?>

Expected result:
----------------
I expect the file to be delivered without error!

Actual result:
--------------
File downloads, but won't open due to length error.

-- 
Edit bug report at http://bugs.php.net/?id=37967&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=37967&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=37967&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=37967&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=37967&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=37967&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=37967&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=37967&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=37967&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=37967&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=37967&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=37967&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=37967&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=37967&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=37967&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=37967&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=37967&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=37967&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=37967&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=37967&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=37967&r=mysqlcfg

Reply via email to