[英]Include files from parent to other directories
我正在建立一個網站,並且在根文件夾中有index.php。 其他頁面最多可容納2個文件夾,並按不同類別分開。
因此index.php文件將是正確的;
<?php include ('/inc/head.php'); ?>
但是其他頁面必須是;
<?php include ('../inc/head.php'); ?> or <?php include ('../../inc/head.php'); ?>
但這會破壞包含文件本身中css和腳本文件的相對路徑,因為它們隨后無法正確映射! 有什么辦法嗎?
您是在談論在head.php
設置的head.php
嗎? 為什么不只使用絕對路徑? 因此,與其使用css/style.css
不如使用/css/style.css
等。
好的,所以我很困惑,在頁腳和頭部以及“包含”中設置了相對路徑。
所以對於解決head
和footer
部分是,
<script src="../../js/bootstrap.min.js" type="text/javascript"></script>
如@ultranaut所述,應將其設置為絕對路徑:
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
如果頁面離根目錄深兩個文件夾,則include
應當為:
<?php include ('../../inc/head.php'); ?>
希望這對其他新手也有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.