PHP Curl Save Dynamic Image From VK
<p>I am trying to save an image from VK to a folder. However the image does not save correctly. </p>

<p>The code I use is:</p>

<pre><code>// imageFromURL (Save an image from a URL)
function imageFromURL($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);
}

imageFromURL('https://vk.com/captcha.php?sid=698254154192&amp;s=1', 'Image/Captcha.png');
</code></pre>

<p>I think it must not be a standard image format? How could I save this and make sure it was a png format image with CURL?</p>