Search code examples
phpfacebookcurlprofileimage

How to save save user's facebook profile picture to my domain/website data using php


i want to save the user's profile picture of facebook to my disk, it is more like scrapping user's profile picture db when they registered first.'

for example here is the url.

https://graph.facebook.com/{id}/picture

i want to save it under a specific directory. also, if there is not picture, i want to download the default placeholder as well, which is GIF. the above url is actually having a placeholder only.

i am beginner in php, please explain me in detail.


Solution

  • <?php
    $image = file_get_contents('https://graph.facebook.com/100003027438870/picture'); // sets $image to the contents of the url
    file_put_contents('/path/image.gif', $image); // places the contents in the file /path/image.gif
    ?>