douliao5550 2013-11-06 21:27
浏览 56
已采纳

我的require_once路径出了什么问题?

I've switched my files over from a local environment to my vps and now my facebook notification isn't working even thought I'm pretty sure I've updated all the paths correctly. I've tried writing the require path numerous ways. I'm doing a "$.post" from jquery to a php page where the facebook notification is sent and am getting this error:

<b>Fatal error</b>:  Class 'Facebook' not found in 

<b>/home/zjkkvcxc/public_html/accepted.php</b> on line <b>9</b><br />

//THIS IS MY PHP REQUIRE PATH. 

require_once('php-sdk/facebook.php') ;

//IN MY LOCAL ENVIRONMENT I WAS USING THIS PATH BECAUSE IT WAS THE ONLY ONE THAT WORKED. THIS DOESN'T WORK ON MY VPS THOUGH. 

require_once(dirname(__FILE__).'/php-sdk/facebook.php') ;
  • 写回答

11条回答 默认 最新

  • douyimin1083 2013-11-15 19:41
    关注

    I have faced issues like this before, and the best way to handle this is to set your true filepath as a variable & prepend that to your includes/requires. Becuase the whole dirname(__FILE__) setup can act oddly in different environments especially those that use symbolic links. Explicitly stating where files are to be set is the best solution.

    So let’s assume this is your codebase path; as per your example:

    /home/zjkkvcxc/public_html/
    

    Set that as a variable that all of your pages load in some way like this:

    $BASE_PATH = '/home/zjkkvcxc/public_html/';
    

    And now when you make calls to the file system for your app, do this:

    require_once($BASE_PATH . 'php-sdk/facebook.php');
    

    What is nice about a setup like this is that you can make your app portable between environments by just changing $BASE_PATH to match your local environment. Like this might be a path for a MAMP (Mac OS X LAMP) setup:

    $BASE_PATH = '/Application/MAMP/htdocs/';
    

    Regarding how odd __FILE__ can act in symlinked environments, read up here:

    Since PHP 4.0.2, _ FILE _ always contains an absolute path with symlinks resolved whereas in older versions it contained relative path under some circumstances.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(10条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据