php路徑有關問題

來源:互聯網
上載者:User
php路徑問題
1、如果目錄結構簡單,可以通過調整包含檔案的階層來解決,仍然使用相對路徑。
3、結合使用絕對路徑和相對路徑,有時為了趕進度可以先行讓項目通過。
4、使用dirname(__FILE__)擷取當前檔案的目錄路徑,比如:
require_once(dirname(__FILE__)."../../include/cfg.php");
5、使用下面的這個語句可以把目前的目錄設定為當前檔案的目錄路徑,也較為方便,尤其是交叉引用的時候非常有用。
chdir(dirname(__FILE__));
6、對於使用虛擬機器主機的使用者可以在包含檔案之前使用set_include_path()函數,比如:
set_include_path(‘./’.PATH_SEPARATOR.dirname(__FILE__));
require_once(‘include/cfg.php’);
7、通過輔助設定php設定檔中的的include_path參數進行查詢路徑,include_path是指將要用到的包含檔案所在的目錄,可以將經常include檔案放到一個統一的目錄裡,然後把這個目錄設定在設定檔php.ini的include_path參數後面,在需要使用這些包含檔案的時候只需要包含其名稱即可,比如就可以了,而實際上metsky_cfg.php檔案則是存在設定的檔案目錄裡。
附PHP.ini檔案中include_path部分內容:
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "path1;path2"
;include_path = ".;c:phpincludes"
;
; PHP's default setting for include_path is ".;/path/to/php/pear"
; http://php.net/include-path
include_path = ".;D:\xampp\php\PEAR"

; The root of the PHP pages, used only if nonempty.
; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root
; if you are running php as a CGI under any web server (other than IIS)
; see documentation for security issues. The alternate is to use the
; cgi.force_redirect configuration below
; http://php.net/doc-root
doc_root =

; The directory under which PHP opens the script using /~username used only
; if nonempty.
; http://php.net/user-dir
user_dir =

; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
; extension_dir = "ext"
extension_dir = "D:\xampp\php\ext"

......
8、通過.htaccess設定檔進行路徑修改也可以達到上一條類似的效果,比如
php_value include_path "./include"


ref:http://www.metsky.com/archives/323.html
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.