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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大