douchuopiao9002 2016-09-22 14:43
浏览 43
已采纳

一个文件包含另一个目录中有链接的文件,如何设置链接的相对路径?

my project directory as follows.

root 
  css
  img  
  src
    login 
       login.php
    dashboard
          basic
              header.php
              footer.php
              profile.php
              manage.php 
          department
              add_depart.php
    configuration
          config.php

Here the header.php included profile.php, manage.php , add_depart.php and config.php.

In the header.php have links point to the another files that are kept in basic folder. My problem is when i include the header.php in add_depart.php and config.php the links are not working. I know include only copy the file into add_depart.php. the links cant access within department folder.

How can i set relative path for the links inside the header.php can access the links provided by header from basic,department,and configuration folders.

I am also tried with getcwd() , dirname(__FILE__) .

Please Help.

Header.php

$path_r = $_SERVER['DOCUMENT_ROOT'];
$path_l = $path_r . '/root/src/dashboard/basic/';
 <li class="dropdown">
    <a href="#" data-target="#" class="dropdown-toggle" data-toggle="dropdown"> Settings <b class="caret"></b></a>
    <ul class="dropdown-menu">
        <li><a href="<?php echo $path_l ?>/profile.php">Profile</a></li>
        <li><a href="<?php echo $path_l ?>/config.php">Config</a></li>
        <li class="divider"></li>
        <li><a href="logout.php">Logout</a></li>
    </ul>
</li>
  • 写回答

1条回答 默认 最新

  • duanji9311 2016-09-22 14:55
    关注

    You're confusing the file system paths with the URL path.

    $_SERVER['DOCUMENT_ROOT'] contains the absolute path to the document root on your server (the file system), not the URL. The same goes for getcwd() and dirname().

    Just start the URLs with a slash: <a href="/path/to/profile.php" etc, and the URL's will be the same no matter where you include it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题