1

I have to download a png file and use it for Image Processing in php. I want to save this image: /favicon?domain=http://facebook.com/">https://plus.google.com//favicon?domain=http://facebook.com/ into my local folder and perform image processing operations over it.

When I am doing this, its working fine:

$url = 'http://s.wordpress.org/about/images/color-blue.png';
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));

but this is not working a file try1.png is getting created of 0kb

$url = "https://plus.google.com/_/favicon?domain=http://facebook.com/";
$img = 'try1.png';
file_put_contents($img, file_get_contents($url));

Please help. Regards, Suyash

jnovacho
  • 2,825
  • 6
  • 27
  • 44
Suyash Dixit
  • 907
  • 9
  • 20

1 Answers1

1

Please try this:

<?php

$url = "https://plus.google.com/_/favicon?domain=http://facebook.com/";
$img = 'try1.png';

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch); 
curl_close($ch);  

file_put_contents($img, $result);

?>
Dave Chen
  • 10,887
  • 8
  • 39
  • 67
  • I am trying to save favicons from google api using your code but it doesn't work. Could it be something with my php configuration? – Kareem Dec 16 '15 at 18:10