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 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?