php - Download a image from SSL using curl? -
how download image curl (https site)?
file saved on computer why blank (0kb)?
function save_image($img,$fullpath){ $ch = curl_init ($img); curl_setopt($ch, curlopt_header, 1); curl_setopt($ch, curlopt_returntransfer, 0); curl_setopt($ch, curlopt_binarytransfer,1); curl_setopt ($ch, curlopt_followlocation, 0); $rawdata=curl_exec($ch); curl_close ($ch); $fp = fopen($fullpath,'w'); fwrite($fp, $rawdata); fclose($fp); } save_image("https://domain.com/file.jpg","image.jpg");
curl_setopt($ch, curlopt_returntransfer, 0);
should be:
curl_setopt($ch, curlopt_returntransfer, 1);
so curl knows should return data , not echo out.
additionally, have more work ssl certs accepted curl:
using curl in php access https (ssl/tls) protected sites
edit:
given usage, should set curlopt_header false alix axel recommended.
in terms of ssl, hope you'll take time read link suggested, there few different ways handle ssl, , fix alix recommended may ok if data isn't sensitive, negate security, forces curl accept server certs.
Comments
Post a Comment