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

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、這幾天整理一份很亂的代碼,這才意識(shí)到php 對(duì)include 處理不是一般的賤:別的編程語言在處理include 中的相對(duì)目錄時(shí),都是以當(dāng)前處理的文件作為基準(zhǔn)。也就是說,如果A 包含B ,B 包含C 時(shí),C 再包含一個(gè)含相對(duì)路徑的文件,那么路徑是相對(duì)于C 的。這樣的處理很自然,符合人們的直覺,也便于開發(fā)出路徑無關(guān)的程序包??墒荘HP 不這樣,它優(yōu)先相對(duì)工作目錄來處理,并且如果路徑中包含. . 的話,則只相對(duì)于工作目錄。也許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 語句會(huì)因此要寫得長一些,但是一個(gè)字,值!PHP 代碼 $_SERVER'DOCUMENT_ROOT'This method allows you to specify a path relative to the web server doc_root for fi

3、le inclusion.這也是許多項(xiàng)目在采用的一種不錯(cuò)的方式,就我看來,缺點(diǎn)是,整個(gè)項(xiàng)目不方便移動(dòng)。例如你一開始放置在 的位置,其他文件包含這個(gè)共有文件)。特別是當(dāng)你同一份代碼放多處時(shí)(例如一個(gè)測試環(huán)境和一個(gè)正式環(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?這種方式感覺稍嫌麻煩了點(diǎn),隨時(shí)要記得恢復(fù)工作目錄也不是容易的事。寫完這句話后,我隨后寫了幾個(gè)測試文件,發(fā)現(xiàn)這種方式的最重要缺點(diǎn)不在麻煩,而在它的副作用:改變了工作目錄,這會(huì)導(dǎo)致程序邏輯出錯(cuò)。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.這是最方便的方式,但不是沒有缺點(diǎn)。首先,有時(shí)候你不見得有權(quán)限修改配置。其次,當(dāng)不同路徑下的文件名有重復(fù)的時(shí)候,你會(huì)被搞糊涂的(就算你不會(huì),你的維護(hù)者呢)。 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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論