Php ';致命错误:类';卷曲文件';未找到';用于';将照片上载到用户';s时间表';

Php ';致命错误:类';卷曲文件';未找到';用于';将照片上载到用户';s时间表';,php,facebook,facebook-graph-api,facebook-php-sdk,facebook-apps,Php,Facebook,Facebook Graph Api,Facebook Php Sdk,Facebook Apps,我刚刚尝试使用Facebook PHP SDK开发一个Facebook应用程序。Facebook开发者网站中给出的示例代码如下 <?php // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-sdk/ require_once('php-sdk/facebook.php');

我刚刚尝试使用Facebook PHP SDK开发一个Facebook应用程序。Facebook开发者网站中给出的示例代码如下

        <?php
  // Remember to copy files from the SDK's src/ directory to a
  // directory in your application on the server, such as php-sdk/
  require_once('php-sdk/facebook.php');

  $config = array(
    'appId' => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
    'fileUpload' => true,
    'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();

  $photo = './mypic.png'; // Path to the photo on the local filesystem
  $message = 'Photo upload via the PHP SDK!';
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {

      // We have a user ID, so probably a logged in user.
      // If not, we'll get an exception, which we handle below.
      try {

        // Upload to a user's profile. The photo will be in the
        // first album in the profile. You can also upload to
        // a specific album by using /ALBUM_ID as the path 
        $ret_obj = $facebook->api('/me/photos', 'POST', array(
                                         'source' => new CURLFile($photo, 'image/png'),
                                         'message' => $message,
                                         )
                                      );
        echo '<pre>Photo ID: ' . $ret_obj['id'] . '</pre>';
        echo '<br /><a href="' . $facebook->getLogoutUrl() . '">logout</a>';
      } catch(FacebookApiException $e) {
        // If the user is logged out, you can have a 
        // user ID even though the access token is invalid.
        // In this case, we'll get an exception, so we'll
        // just ask the user to login again here.
        $login_url = $facebook->getLoginUrl( array(
                       'scope' => 'photo_upload'
                       )); 
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {

      // No user, print a link for the user to login
      // To upload a photo to a user's wall, we need photo_upload  permission
      // We'll use the current URL as the redirect_uri, so we don't
      // need to specify it here.
      $login_url = $facebook->getLoginUrl( array( 'scope' => 'photo_upload') );
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>

但是当我运行程序时,它显示一个错误
“致命错误:类”CURLFile“找不到”
。在搜索解决方案时,我发现新的PHP Facebook SDK没有“CURLFile”类。有人能帮我用新的SDK代码“将照片发布到用户时间线”吗


提前感谢。

您是否尝试通过取消注释该行来在PHP中启用cURL

new \CurlFile($photo)
在xampp\apache\bin\php.ini中,然后重新启动apache服务

您可以通过phpinfo()进行检查


同时根据检查php版本,可能需要添加反斜杠:

'source' => class_exists('CurlFile', false) ? new CURLFile($photo, 'image/png') : "@{$photo}"
如果不起作用,可能会检查
CurlFile
是否存在。如果它不存在,则需要直接传递tmp
filename.fileExtension

$ret_obj = $facebook->api('/me/photos', 'POST', [
    'image'   => '@' . realpath($photo),
    'message' => '$message'
]);
如果else条件下的
$photo
格式为
filename.fileExtension

请尝试以下操作:

$ret_obj = $facebook->api('/me/photos', 'POST', [
    'image'   => '@' . realpath($photo),
    'message' => '$message'
]);
// If you're not using PHP 5.5 or later, change the file reference to:
// 'source' => '@/path/to/file.name'
这对我有用

除了使用
realpath
,请注意
'source'
现在是
'image'

请参阅:

卷曲文件
仅在PHP5>=5.5.0中可用

正如Facebook的例子所说:


@HassanMagdy Windows 7 64位。可能您的php版本还不支持php5.5。您的意思可能是
$message
,而不是
'$message'
?在
卷曲文件前面添加\对我来说很有效。谢谢