|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #16969 Improper readfile filesize after download
Submitted: 2002-05-02 12:19 UTC Modified: 2002-05-02 13:26 UTC
From: fred dot malone at planitcabnetware dot com Assigned:
Status: Not a bug Package: IIS related
PHP Version: 4.2.0 OS: Windows 2000 Server
Private report: No CVE-ID: None
 [2002-05-02 12:19 UTC] fred dot malone at planitcabnetware dot com
On my NT Srv 4 with IIS 4 and 2000 Srv with IIS 5 I have had the same problem.  Running PHP 4.2, when I use readfile to download a binary file, the file size is two bytes greater than the original file size.  The file is an executable file, and it has happened to more than one file.

If you need any other information, let me know.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-02 12:43 UTC] fred dot malone at planitcabnetware dot com
Also, I checked the file size using the filesave function and it reports the correct file size.

I have tried this using MSIE 6 and Netscape 6.  I tried this from both WinXP and Win2000 workstations.  

My function looks like:

function DownloadFile($filename)
    // Check filename
    if (empty($filename))
        return FALSE;
    // Create download file name to be displayed to user
    $saveasname = basename($filename);
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.filesize($filename));

    $browser = $_SERVER["HTTP_USER_AGENT"];
    if (preg_match('/MSIE 5.5/', $browser) 
        || preg_match('/MSIE 6.0/', $browser))
        header('Content-Disposition: filename="'.$saveasname.'"');
       header('Content-Disposition: attachment; filename="'.$saveasname.'"');
    header('Content-Transfer-Encoding: binary');

    // Output file
    // Done
    return TRUE;
 [2002-05-02 12:53 UTC]
Does the end of your script have a blank line after the ?>,
or do you have an auto_prepend file or some other include file that has this??

 [2002-05-02 12:59 UTC] fred dot malone at planitcabnetware dot com
Actually, it does.  Two blank lines to be precise.  I just removed those lines and tested and it works fine.  Sorry about that.  Shows I am new to PHP, but I love it so far.

 [2002-05-02 13:26 UTC]
user error -> bogus
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Jun 07 13:03:43 2023 UTC