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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?