note 99823 rejected from function.header by danbrown
| From: | danbrown@php.net | Date: | Sun, 23 Jan 2011 17:27:56 +0000 |
| Subject: | note 99823 rejected from function.header by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-176206@lists.php.net to get a copy of this message | ||
Note Submitter: dalibor dot sojic at gmail dot com
----
I'm trying to get image from google charts api via curl.
Here is part of the code:
<?php
header('Content-Type: image/png');
echo $this->chart->getChart();
___________________________
private function getChart() {
$ch = curl_init('http://chart.apis.google.com/chart?chid='
.md5(uniqid(rand(), true)).'&'.
http_build_query($this->_post));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POST,count($this->_post));
curl_setopt($ch,CURLOPT_POSTFIELDS,
http_build_query($this->_post));
$response = curl_exec($ch);
$file = fopen('/path/to/test/graph.png', 'w+');
fwrite($file, $response);
fclose($file);
return $response;
}
?>
The problem after calling this I get error "The image can not be displayed, because it contains
errors".
If I open saved file /path/to/test/graph.png it is OK.
The difference is 2 bites at the beginning of received response. \r\n is prepended.
How can fix this?