我之前的示例中存在一些链接问题,所以我在服务器上下载了图像并从那里显示它是我的代码
$username = 'dipen';
$password = 'yourpassword';
$url = "https://graph.yourdomain.com/";
$cookie = "cookie.txt";
$path = "tempcookie";
$postdata = "login_username=".$username."&login_password=".$password."&action=login";
$ch =curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$agent = $_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch,CURLOPT_USERAGENT, $agent);
curl_setopt($ch,CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_COOKIESESSION, true);
curl_setopt ($ch,CURLOPT_REFERER, $url);
curl_setopt ($ch,CURLOPT_POST, 1);
curl_setopt ($ch,CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_COOKIEJAR, $path.'/'.$cookie);
curl_setopt($ch,CURLOPT_COOKIEFILE, base_url().$path.'/'.$cookie);
$result = curl_exec ($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
if(!empty($corporate_graph_id))
{
$corporate_graph_id = $corporate_graph_id[0]['grpah_id'];
$url1 =' https://graph.yourdomain.com/graph_image.php?action=view&local_graph_id='.$corporate_graph_id.'&rra_id=3';
curl_setopt($ch, CURLOPT_URL, $url1);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$answer = curl_exec($ch);
if (curl_error($ch)) {
echo curl_error($ch);
}
$fp = fopen($path.'/'.$corporate_graph_id.'.jpg','w');
fwrite($fp, $answer);
fclose($fp);
$img_path = base_url().$path.'/'.$corporate_graph_id.'.jpg';
echo '<img src="'.$img_path.'" /><br/>';
}
curl_close($ch);