0

I have the following code to upload image to my photos

  $args = array('message' => 'Photo Caption');
          $args['image'] = '@' . realpath('http://sawalpk.com/storyboard_server/outputImage.png');

          $data = $facebook->api('/me/photos', 'post', $args);
          print_r($data);

If I put the image as realpath('someImage.png') It works. Remember the someImage.png is found the the same directory. While with the url of an external image it do not uploads and returns no data to debug. Any guru here to help me. Thanks in advance.

Gunah Gaar
  • 525
  • 2
  • 10
  • 28

2 Answers2

3

You have to download the remote (for e.x. via CURL or file_get_contents()) file to the server and pass it via realpath() locally.

In fact, you send the request to Facebook Graph API, so you cannot include remote file.

Related problem: Upload a remote photo to an upload

I preffer CURL because of efficiency: https://stackoverflow.com/questions/555523/file-get-contents-vs-curl-what-has-better-performance.

Community
  • 1
  • 1
Athlan
  • 6,389
  • 4
  • 38
  • 56
2

this works for me:

$picUrl = 'http://sawalpk.com/storyboard_server/outputImage.png';
$photoId = $facebook->api("me/photos","POST",array('url'=>$picUrl,'message'=>"Photo caption"));

set 'url' parameter if you have image url instead of real path.

Smita
  • 4,634
  • 2
  • 25
  • 32