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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?