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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)