[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";

This entry was posted in PHP, 程式設計, 網頁撰寫. Bookmark the permalink.

Leave a Reply

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