|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49178 Incomplete file downloads
Submitted: 2009-08-06 12:21 UTC Modified: 2009-08-14 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: moricio at gmail dot com Assigned:
Status: No Feedback Package: cURL related
PHP Version: 5.2.10 OS: Windows 2003 Server SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: moricio at gmail dot com
New email:
PHP Version: OS:


 [2009-08-06 12:21 UTC] moricio at gmail dot com

I have a PHP app where I generate a PDF file, using jasperreports, and 
then mail this file to a subscriber. I use curl and the CURLOPT_FILE 
option to get the pdf file. As soon as I finish getting the file, it 
reports a size that is always an exact multiple of 4Kbytes, even when 
the file is bigger than what PHP reports.

Reproduce code:
Code with error is ...
$ch = curl_init("");
$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
$fpOutput = fopen($tmpfname, "wb");

curl_setopt($ch, CURLOPT_FILE, $fpOutput);
curl_setopt($ch, CURLOPT_HEADER, 0);

echo "filesize: $tmpfname: " . filesize($tmpfname) . "\n";


Code without error is ...
$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
$fpOutput = fopen($tmpfname, "wb");

$ch = curl_init("");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');


echo "filesize: $tmpfname: " . filesize($tmpfname) . "\n";

function read_body($ch, $string)
	global $fpOutput;

	$length = strlen($string);
	if (fwrite($fpOutput, $string) === FALSE) {
		echo "Cannot write to file";
	return $length;

Expected result:
The second piece of code reported in this bug report gives the correct 
file size.

The first piece of code saves the file with the correct size but doesn't 
report it correctly.

This was not happening until I upgraded to PHP 5.2.10 from a previous 
version that I don't remember. :(

Hope you can find inside what is going on.

Best regards and thanks for a great piece of software.

Mauricio Ramirez

Actual result:
The first piece of code reports 4096 bytes for the page.

The second piece of code reports (today!) 6672 bytes which is the right 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-06 13:19 UTC]
Please try using this snapshot:
For Windows:

 [2009-08-14 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-10-11 08:49 UTC] phpspam at ethaniel dot com
I confirm this on PHP 5.2.10 (cli) running on Freebsd 7.2.
 [2009-10-11 09:43 UTC] phpspam at ethaniel dot com
This has been fixed in 5.2.11
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Aug 02 02:01:24 2021 UTC