PHP途徑相關 dirname,realpath,FILE_

來源:互聯網
上載者:User
PHP路徑相關 dirname,realpath,__FILE__

?比如:程式根目錄在:E:\wamp\www 中

1. __FILE__ 當前檔案的絕對路徑

如果在index.php中調用 則返回 E:\wamp\www\index.php

下面再看一下 程式根目錄的目錄結構

如果在 c_system_base.php中調用__FILE__ 則返回:

E:\wamp\www\zb_system\function\c_system_base.php

2.dirname 返回目前的目錄的上級目錄 或當前檔案所在的目錄 (結尾不帶/)

一般跟__FILE__聯合使用

如果在 c_system_base.php中調用dirname(__FILE__) 則返回

E:\wamp\www\zb_system\function (文說件返回所在目錄)

如果調用 dirname(dirname(__FILE__)) 則返回

E:\wamp\www\zb_system (目錄返回上級目錄)

realpath() 方法 返回當前檔案的絕對路徑 或 相對根目錄的路徑

如果在 c_system_base.php中調用realpath(__FILE__) 則返回

E:\wamp\www\zb_system\function\c_system_base.php

realpath('/') 返回磁碟根目錄 E:\

realpath('./') 返回根目錄 E:\wamp\www

realpath('../') 返回相對程式根目錄的上級目錄

也可以和dirname配合使用 一般還會加上幾個相對路徑../ (前面要加/ 即:/../)

realpath(dirname(__FILE__)) 返回 E:\wamp\www\zb_system\function

realpath(dirname(__FILE__).'/../') 返回 E:\wamp\www\zb_system

realpath(dirname(__FILE__).'/../../') 返回 E:\wamp\www

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.