dongtie0929 2014-06-29 12:37
浏览 103
已采纳

使用require_once在php中包含文件时出错

This is my app. root:

htdocs

    core/

        init.php

    classes/

        DB.php
        POST.php

    ajax/

        post_feeds.php

This is my post_feeds.php;

require_once '../core/init.php';

The file init.php is there but I don't understand why I am getting this error.

Warning: require_once(classes/DB.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\core\init.php on line 9

Fatal error: require_once(): Failed opening required 'classes/DB.php' (include_path='.;C:\php\pear') in C:\Apache24\htdocs\core\init.php on line 9

It gives me no error in my init.php file when I require_once 'classes/DB.php';

This is init.php

session_start();

date_default_timezone_set('Etc/GMT+2');
//date_default_timezone_set('Europe/Tirane');

//autoload for classes.
require_once 'classes/DB.php';
require_once 'classes/USER.php';
require_once 'classes/NOTIFICATION.php';

if (isset($_COOKIE["user_id"])) {
    $_SESSION['user_id'] = $_COOKIE['user_id'];
}
  • 写回答

2条回答 默认 最新

  • dps69208 2014-06-29 13:38
    关注

    Try to use an absolute path for including files:

    $root = realpath($_SERVER["DOCUMENT_ROOT"]);
    require_once("{$root}/core/init.php");
    

    Or with dirname:

    require_once(dirname(__FILE__) .'/../core/init.php');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 打开软件提示错误:failed to get wglChoosePixelFormatARB
  • ¥30 电脑误删了手机的照片怎么恢复?
  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了