Hi,
I am having a problem with saving a file from a response to a POST request.
I am using Google Charts API to create a chart using a POST request. I am then trying to save the result as an image.
I am following the API documentation as described here: http://code.google.com/apis/chart/docs/post_requests.html
Here is my code:
$file = fopen($url, 'r', false, $context);
$file2 = fopen("test.png", 'w');
while (!feof($file)) {
$buffer = fgets($file, 8192);
fwrite($file2, $buffer);
}
fclose($file);
It saves the image partially, up to 20k or so, leaving the bottom part of the image unsaved.
(edit) Here is the working code, using curl:
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_FILE, $file);
curl_setopt($handle,CURLOPT_POST,count($request));
curl_setopt($handle, CURLOPT_POSTFIELDS, $request_string);
$data = curl_exec($handle);