使用Facebook PHP SDK:Uncaught CurlException:26:创建formpost dat失败
我看了几篇关于这个错误消息的stackoverflow文章,但没有一篇对我有用 我想上传一张照片到facebook:使用Facebook PHP SDK:Uncaught CurlException:26:创建formpost dat失败,php,facebook,api,curl,sdk,Php,Facebook,Api,Curl,Sdk,我看了几篇关于这个错误消息的stackoverflow文章,但没有一篇对我有用 我想上传一张照片到facebook: public function uploadPhoto($path){ $photoSettings = array( 'access_token'=> $this->facebook->getAccessToken(), 'name' => 'uploaded foto', 'source' =&g
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);
}
调用此函数时,会收到以下错误消息:
未捕获的CurlException:26:创建formpost数据失败
我100%确信我要上传的图像存在(并且路径正确)
这是我的facebook初始化:(fileUpload为true)
我真的不明白为什么会出现这样的错误,因为我的代码似乎是正确的。您认为我的服务器/服务器的cURL配置可能有问题吗?我对卷发不太了解
我希望你能帮助我!我期待您的回答:-)
您好,
Andreas您的realpath($path)
没有指向实际的服务器映像位置。如果$path
是图像的完整路径,则使用'source'=>'@$路径
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;
}
}
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;
}
}