I am trying to save an image from VK to a folder. However the image does not save correctly.
The code I use is:
// 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&s=1', 'Image/Captcha.png');
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?