[英]PHP Include path specifically always at root document
我在理解包含路徑及其寫法時含糊不清,我知道如何在ini
文件中設置它們以及如何在功能上進行設置,而set_include_path
不會每次都精確地設置set_include_path
。
因此,我有一個管理員自動加載文件,該文件包含在所有標頭中以注冊spl_autoload_register
函數。 我只是不斷在error_log
文件中得到錯誤。 它說
PHP Fatal error: Class 'Configurate' not found in
/home/~username~/public_html/testing_ini.php on line 5
因此,我要尋找的是無論我身在何處,如何將include路徑始終設置為public_html
目錄之前的目錄?
我嘗試將包含路徑設置為
.:/opt/alt/php5/usr/share/pear:/opt/alt/php5/usr/share/phphome/~username~/classes/Configurate.php
但是我仍然得到錯誤。 有任何幫助和一些技巧可以幫助您理解這件事嗎? 我吮吸relative
路徑
根據要求的spl_autoload_register
函數
<?php
$ini = parse_ini_file("configurations.ini",true);
foreach($ini as $section) {
foreach($section as $key=>$value ) {
define("__".strtoupper($key)."__",$value);
}
}
//if(__USERNAME__ == null) {
// header("Location: /setup.php?step=1");
// exit();
//}
spl_autoload_register(function($class) {
try {
if(!file_exists("../classes/{$class}.php")){
throw new Exception("/classes/{$class}.php does not exist error on line ". __LINE__." in file ". realpath(__FILE__));
} else
require_once "../classes/{$class}.php";
} catch (Exception $ex) {
echo $ex->getMessage()."<br>";
echo $ex->getCode();
}
});
getcwd()
和許多其他方法對我不起作用。 盡管我確實找到了一種對任何目錄都適用的方法。
set_include_path(
dirname( $_SERVER["DOCUMENT_ROOT"] )
);
希望這可以幫助其他任何希望脫離文檔根目錄並像我一樣使用它的人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.