问题
I had a look at several stackoverflow posts about this error message, but none of them worked for me.
I want to upload a photo to facebook:
public function uploadPhoto($path){
$photoSettings = array(
'access_token'=> $this->facebook->getAccessToken(),
'name' => 'uploaded foto',
'source' => '@' . realpath($path)
);
$photo = $this->facebook->api('me/photos','POST',$photoSettings);
}
When i call this function, i get the following error message:
Uncaught CurlException: 26: failed creating formpost data
I am 100% sure that the image i want to upload exists (and the path is correct).
This is my facebook initialization: (fileUpload is true)
$this->facebook = new Facebook(array(
'appId' => $this->config['appId'],
'secret' => $this->config['appSecret'],
'fileUpload' => true,
'cookie' => true
));
I really don't understand why i get that error because my code seems to be correct. Do you think there could be a problem with my server / the server's cURL configuration? I dont know much about cURL.
I hope you can help me! I am looking forward for your answers :-)
Greetings, Andreas
回答1:
Your realpath($path)
is not pointing to the actual server image location. If $path
is the complete path of the image, then use 'source' => '@' . $path
instead.
回答2:
I kept getting “CurlException: 26: failed creating formpost data”
Here is my working code for uploading a photo from the same directory as the PHP page communicating with Facebook:
$facebook = new Facebook(array(
'appId' =>'*****',
'secret' =>'*******',
'fileUpload' => true,
'cookie' => true
));
$user = $facebook ->getUser();
if($user)
{
$facebook->setFileUploadSupport(true);
$args = array(
'message' => 'TEst from App.',
'image' => '@' . realpath('awesome.jpeg')
);
try {
$data = $facebook->api('/me/photos', 'post', $args);
} catch(FacebookApiException $e) {
echo "ERROR: " . $e;
}
}
来源:https://stackoverflow.com/questions/11434379/working-with-facebook-php-sdk-uncaught-curlexception-26-failed-creating-formp