doulong4169 2013-09-23 19:06
浏览 182

如何让require_once从上面的目录中获取文件?

I'm trying to set up a site of which I was not the original owner, on a new server - In Apache2, the document root has been set to /var/www/html, which is where the index.php that I want to be the default 'homepage' is located.

There are a number of files in other directories in www. For an example, /common/cachelite/Lite.php can also be found in /var/www.

The php in index.php references this using require_once, like below:

error_reporting(E_ALL);
ini_set('Display_errors','On');
require_once('../common/cachelite/Lite.php');

But throws the following error, which I have taken from my Apache2 error.log:

PHP Fatal error:  require_once(): Failed opening required '../common/cachelite/Lite.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/html/index.php on line 4

The file itself is definitely there, so can anybody shed some light on this issue for me? What's going on?

  • 写回答

3条回答 默认 最新

  • dsv73806 2013-09-23 19:14
    关注

    I have run in to this problem a few times and always fix it like so.

    $file = dirname(dirname(__file__));
    require_once($file ."/common/cachelite/Lite.php");
    

    To narrow it down further.

    try this if doing it on the web server and not command line add <pre></pre> tags.

    echo __file__ . "
    ";
    echo dirname(__file__). "
    ";
    echo dirname(dirname(__file__)). "
    ";
    

    My next thought is, file permissions or misspelled words.

    评论

报告相同问题?

悬赏问题

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