[PHP] 根目錄的路徑

感謝PTT網友appleboy46提供以下做法:

在根目錄放置 config.php 檔案,裡面定義:
define('Document_root',dirname(__FILE__));

之後每個檔案請寫入:

$root_path = "./";
include($root_path . 'config.php');

之後要 include 任何檔案,都可以直接用 Document_root 來定義

echo Document_root . "/template.php";

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these