cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker mailing list Archives

[ curl-Bugs-2831467 ] Incomplete file downloads.

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Mon, 03 Aug 2009 13:48:14 +0000

Bugs item #2831467, was opened at 2009-08-03 15:13
Message generated for change (Comment added) made by bagder
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2831467&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Mauricio Ramirez (moricio)
Assigned to: Daniel Stenberg (bagder)
Summary: Incomplete file downloads.

Initial Comment:
Hi.

I have a PHP app where I generate a PDF file, using jasperreports, and then mail this file to a subscriber. I get the file from the website using this code:

--
		$ch = curl_init($rsPR->fields("strURL"));
		$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
		$fpOutput = fopen($tmpfname, "wb");
		curl_setopt($ch, CURLOPT_FILE, $fpOutput);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_exec($ch);
		curl_close($ch);
		fclose($fpOutput);
		echo "filesize: $tmpfname: " . filesize($tmpfname) . "\n";
--
The file, at this point, has a multiple of 16Kbytes inside. The last bytes of the file are not there.
I changed to:
--
		$tmpfname = tempnam(sys_get_temp_dir(), "IPV");
		$fpOutput = fopen($tmpfname, "wb");
		$ch = curl_init($rsPR->fields("strURL"));
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'read_body');
		curl_exec($ch);
		curl_close($ch);
		
		fclose($fpOutput);
		
		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";
        die();
    }
    return $length;
}
--
and the file is saved 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
----------------------------------------------------------------------
>Comment By: Daniel Stenberg (bagder)
Date: 2009-08-03 15:48
Message:
You're talking about problems with the PHP/CURL binding. This tracker is
purely for curl and libcurl specific bugs.
I suggest you head over to http://bugs.php.net and file your problem there
in case it isn't there already.
----------------------------------------------------------------------
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=2831467&group_id=976
Received on 2009-08-03

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET