PHP中include路徑的解決方法匯總_第1頁
PHP中include路徑的解決方法匯總_第2頁
PHP中include路徑的解決方法匯總_第3頁
PHP中include路徑的解決方法匯總_第4頁
PHP中include路徑的解決方法匯總_第5頁
全文預覽已結(jié)束

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、這幾天整理一份很亂的代碼,這才意識到php 對include 處理不是一般的賤:別的編程語言在處理include 中的相對目錄時,都是以當前處理的文件作為基準。也就是說,如果A 包含B ,B 包含C 時,C 再包含一個含相對路徑的文件,那么路徑是相對于C 的。這樣的處理很自然,符合人們的直覺,也便于開發(fā)出路徑無關的程序包。可是PHP 不這樣,它優(yōu)先相對工作目錄來處理,并且如果路徑中包含. . 的話,則只相對于工作目錄。也許PHP 這樣處理有它的理由,有誰知道的不妨告訴我。下面是解決這一問題的幾種方式: _FILE_FILE_ always equals to the real path of

2、a php script regardless whether it's included._FILE_ helps you specify the file to include using relative path to the including file. 這種方法首選推薦。雖然你的include 語句會因此要寫得長一些,但是一個字,值!PHP 代碼 $_SERVER'DOCUMENT_ROOT'This method allows you to specify a path relative to the web server doc_root for fi

3、le inclusion.這也是許多項目在采用的一種不錯的方式,就我看來,缺點是,整個項目不方便移動。例如你一開始放置在 的位置,其他文件包含這個共有文件)。特別是當你同一份代碼放多處時(例如一個測試環(huán)境和一個正式環(huán)境),你改文件也不好改。PHP 代碼 chdir(The include looks for file relative to current working directory. We can use thisfeature. It's really a "fancy" way, but I'm not sure whether it'

4、s safe all the time. Who knows?這種方式感覺稍嫌麻煩了點,隨時要記得恢復工作目錄也不是容易的事。寫完這句話后,我隨后寫了幾個測試文件,發(fā)現(xiàn)這種方式的最重要缺點不在麻煩,而在它的副作用:改變了工作目錄,這會導致程序邏輯出錯。rainfalling at yahoo dot com (21-Sep-2005 01:06This is yet another way to include files relative to the current file. I find it easier if you have a lot of includes.PHP 代碼 se

5、t_include_path(This way is the most convenient way but it's not without flaws. First, not in all cases you have permission to change server configuration. Second, if there are many path specified in include_path, the actually included file may not be the one you expected because there may be fil

6、es of the same name under different directories.這是最方便的方式,但不是沒有缺點。首先,有時候你不見得有權限修改配置。其次,當不同路徑下的文件名有重復的時候,你會被搞糊涂的(就算你不會,你的維護者呢)。 auto_prepend_file and auto_append_file in php.iniThis almost the best way if your scripts commonly need a startup script. We can do a lot of useful things in the startup script, for examples, define constants, loadconfigurations. But it's not always OK to change the php.ini settings. Remember the most adaptive applicatio

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論