doz95923 2011-11-13 10:55
浏览 9
已采纳

如何包含来自不同目录的PHP脚本? [重复]

Possible Duplicate:
include file from different directory

I have a site laid out as follows:

  • index.php includes include/code.php
  • config.php
  • include/
    • code.php includes ./config.php
  • admin/
    • index.php includes code.php

When doing the inclusion from the primary index there are no problems, however when I try and include code.php from admin it fails to locate and include config.php

  • 写回答

2条回答 默认 最新

  • drg5577 2011-11-13 11:04
    关注

    You have three options that I can think of:

    1. Specify the files absolute path in your includes, preferably using a constant containing your base directory. For example: require_once BASE_DIR . '/include/code.php';
    2. Specify relative paths from each file. To do this, you prefix the path with dirname(__FILE__) to ensure that the relative path is in fact relative to the current file (and not the executed file). For example: require_once dirname(__FILE__) . '/../include/code.php';
    3. Add your base directory to the include path, and specify the absolute path inside the project directory. For example: require_once '/include/code.php';
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本