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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?