Read php file if I am in a folder

时间:2018-05-28 18:55:08

标签: php

I created a footer.php file:

<footer class="footer">
  <div class="container">
    <div class="row">
      <div class="footer-col col-md-5">
        <p>Copyright © 2018 Nens Events.</p>
      </div>
    </div>
  </div>`

and it is located on a folder like this one: /php/footer.php All I want is to read it on a subfolder like this one: /events/na/1.php

but when I use this code, it doesn't read the footer.php file, does someone know what I am doing wrong?

<?php
echo file_get_contents("/php/footer.php");
?>

1 个答案:

答案 0 :(得分:0)

使用include()require()功能将您的代码加入到您的脚本中。

所以阅读代码(用你的术语)就是这样的         <?php include 'php/footer.php'; ?>

如果站点位于根页面上,请使用这样的绝对路径。 <?php include '/php/footer.php'; ?>

它应该工作!试一试。

使用require('php/footer.php')进行更好的编码。