duanhao7786 2016-05-13 04:53
浏览 27
已采纳

php正确添加所需文件

i have following folder structure.

enter image description here

config.php

<?php
class config {
    const server = "localhost";
}

conn.php

<?php
 require_once './config.php';

firstExample.php

<?php

require_once './db/conn.php';

when i run conn.php there is no errors.but if i run firstExample.php i got following error

Warning: require_once(./config.php): failed to open stream: No such file or directory in C:\wamp\www\testX\db\conn.php on line 2

i do some tests and able to fix the error by changing conn.php to

require_once './db/config.php';

my question is i need to add conn.php from lot of folders,sub folders.so changing like above doesn't work.for example if i run conn.php after above change then again i'm getting same error.

what i want to know is correct way of adding files.so when i add conn.php to any file config.php should be included.

  • 写回答

4条回答 默认 最新

  • duanan1946 2016-05-13 05:09
    关注

    Look at Directory structure

    you do not need to put "./"

    Try:

     require_once 'config.php';
    

    Or you can define path in CONSTANT and use it.

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

报告相同问题?

悬赏问题

  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测