douwen9534 2019-06-05 02:20
浏览 50

问题了解dirname文件位置| PHP

I am practicing writing in php and learning about the php syntax. I'm a bit confused about the following function:

function __construct()
{
    require_once dirname(__FILE__) . '/constants.php';
    require_once dirname(__FILE__) . '/DbConnect.php';
    // opening db connection
    $db = new DbConnect();
    $this->conn = $db->connect();

}

When stating require_once dirname(__FILE__) . '/constants.php'; where is constants.php located?

  • 写回答

2条回答 默认 最新

  • douhushen3241 2019-06-05 02:46
    关注

    dirname(__FILE__) returns the location of the working file (file in which it is written). Lets say you are on window a d the dir to your working file is C:\myproject\phpfiles\workingfile.php The function dirname(__FILE__) will return C:\myproject\phpfiles Thus your file constants.php should be in the folder phpfiles for your program to find it.

    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试