0

I am using following code for storing image in my website dir

 $fb_id=1120381158031234;//eg
 $image = file_get_contents($userArray['picture']['data']['url']);
 file_put_contents('../images/profiles/fb_id'.$fb_id.'.gif', $image);

but getting this error

Warning: file_put_contents(../images/profiles/fb_id_1120381158031234.gif): failed to open stream: No such file or directory in /XXXX/XXXX/XXXX/XXXX/facebook.php on line 48

Warning: Cannot modify header information - headers already sent by (output started at /XXXX/XXXX/XXXX/XXXX/facebook.php:48) in /XXXX/XXXX/XXXX/login-facebook.php on line 38

CBroe
  • 91,630
  • 14
  • 92
  • 150
sunilwananje
  • 714
  • 5
  • 17

1 Answers1

1

First problem:

Your code is running inside facebook.php. Your code tries to reach the folder images as a sibling of the folder facebook.php is in. It fails either when searching for that folder or when searching for the profiles subfolder. Note, that one of these does not exist at the point your code is searching for it or the OS user executing the PHP code does not have write privileges on one of those folders.

Test by running the following code:

echo getcwd();

just before your call to file_get_contents. You will see then where the folders are searched for.

As about the second problem, this excellent post should make things clear about it.

Community
  • 1
  • 1
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175