duanluo9369 2014-05-23 12:54 采纳率: 100%
浏览 250
已采纳

require_once():无法打开所需的'...'(但文件存在)

When I use require_once I get the following error:

"PHP Fatal error: require_once(): Failed to opening required '/Application/Rules/required_file.class.php'"

My directory structure is:

  • Project
    • Application
      • Rules
        • required_file
    • Public
      • Users
        • file

"file" is where I use require_once:

require_once('/Application/Rules/required_file.class.php');

Why the error? Can anyone help me with the solution?

  • 写回答

3条回答 默认 最新

  • douwen7475 2014-05-23 12:59
    关注

    If I got you right, you are calling the

    require_once('/Application/Rules/required_file.class.php');
    

    within the file? That does not work because require_once always relates to the current folder, as long as you do not use absolute paths.

    Instead you need to call

    require_once('../../Application/Rules/required_file.class.php');
    

    because the file you want to include is not in the same folder as your file.

    ../ goes back one folder in the hierarchy.

    ../../ therefore goes back from /Users to /Public and then to /Project, form where you then can go to /Application.


    I think this article might explain the difference between relative and absolute paths quite well.

    The relative path points to a file or directory in relation to where the present file is located.

    The absolute path is the "full path" from the webserver point of view. It is the path that contains the document root. For example /var/www/mydomain.com/.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义