function grab_image($url,$saveto){ $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $raw=curl_exec($ch); curl_close ($ch); if(file_exists($saveto)){ unlink($saveto); } $fp = fopen($saveto,'x'); fwrite($fp, $raw); fclose($fp); }
хэрэглэх заавар:
$url = ‘http://example.com/graph.phpto=1491208200&id=187&from=1491179400&height=135&width=600’;
$img = ‘/var/www/html/images/image.png’;
grab_image($url,$img);