php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37967 forced download error - using output buffer, content-length header & readfile
Submitted: 2006-06-29 22:08 UTC Modified: 2006-06-30 07:26 UTC
From: mmosel at gmail dot com Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.4.2 OS: Unix and Win2k
Private report: No CVE-ID: None
 [2006-06-29 22:08 UTC] mmosel at gmail dot com
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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-30 07:26 UTC] mike@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 22:01:29 2024 UTC