php – How to save facebook profile picture in database?


I have a button that, when clicked, connects to facebook and displays the person's data in a form for registration, in this form a text field that returns the following:'.$fb_id.'/picture?width=300

I would like to save the photo that the link returns to me in the database. I was using file_put_contents('...',file_get_contents()) , but it's not working anymore.


I used this class to solve my problem.

        class cUrl{
            public function file_get_contents_curl($url) 
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_HEADER, 0); 
                curl_setopt($ch, CURLOPT_URL, $url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

                $data = curl_exec($ch);

                return $data;
Scroll to Top