0

I am trying to develop a login to my website functionality with Facebook account using Facebook Graph API.

I am in trouble to retrieve profile image of logged in user because Facebook returns URL but when I try it on the navigator it says that it needs permission to download it.

For example the URL:

https://platform-lookaside.fbsbx.com/platform/profilepic/?asid......

PS : I make the 3 points

I want to know if there is any method to get a correct URL to save it in the database or if there is any method to download the image with PHP, I tried this on my end, but no success.

$img = file_get_contents($dataata['picture']['url']);          
$file = '/img/test.jpg';
file_put_contents($file, $img);

Message returned is :

file_put_contents(/img/test.jpg): failed to open stream: No such file or directory

Any solution?

Ahmed Numaan
  • 1,034
  • 1
  • 10
  • 26
PHPSA
  • 11
  • 4
  • 1
    Possible duplicate of [PHP - Failed to open stream : No such file or directory](https://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – IncredibleHat Aug 06 '18 at 16:00
  • 1
    You are trying to write that file to the ROOT `/img` directory of your server. – IncredibleHat Aug 06 '18 at 16:00
  • @IncredibleHat I make the full URL `http://localhost/img/test.jpg` but the same problem – PHPSA Aug 06 '18 at 16:04
  • 2
    You need to use the full absolute path on the local file system, not URL. – marekful Aug 06 '18 at 16:06
  • @marekful, but sir always when I want to save an image I use this `/img/nameofimage.ext` – PHPSA Aug 06 '18 at 16:08
  • As @marekful mentioned... please understand the differences between file system paths, url paths, and relative/absolute of each. – IncredibleHat Aug 06 '18 at 16:08
  • 1
    You don't have a `/img/` folder in your root partition to start with. You need to use the path to the document root folder of your webserver continued with the path inside that docroot, e.g. `/var/www/myproject/img/nameofimage.jpg` – marekful Aug 06 '18 at 16:09
  • Also look into `__DIR__` for dynamically adjusting to the server environment for where you wish to store url-accessed resources from your php scripts. – IncredibleHat Aug 06 '18 at 16:12
  • @marekful I make the full path `C:\wamp.....` it's work, but if I want to make it on the server I need just to make the URL or what ? – PHPSA Aug 06 '18 at 16:12
  • @marekful sorry for my stupid question, I make like this it's work sir `dirname('public').'/img` How can I give you the correct answer ? – PHPSA Aug 06 '18 at 16:16
  • No worries! You fixed the problem with a few hints from us. – marekful Aug 06 '18 at 16:18
  • Thanks for your helps guys – PHPSA Aug 06 '18 at 16:38

0 Answers0