file_get_contents()解決方案

來源:互聯網
上載者:User
file_get_contents()
這是index.php
PHP code


然後test.php中就一句話:this is a test
這兩個檔案位於同一級目錄,我在瀏覽器中運行時,'this is a test'這句話會被正常打出來,而用命令列運行時卻出現了警告,也沒有輸出'this is a test'.
錯誤如下:
C:\Users\hahaliu>php G:\www\index.php
PHP Warning: file_get_contents(test.php): failed to open stream: No such file
or directory in G:\www\index.php on line 3

Warning: file_get_contents(test.php): failed to open stream: No such file or di
rectory in G:\www\index.php on line 3
然後我將$file改為了絕對路徑
$file = 'G:/www/test.php';
命令列下就能輸出'this is a test',為什麼用相對路徑在命令列下就出錯了?我很困惑,是什麼沒有設定對嗎?



------解決方案--------------------
在不考慮php.ini中include_path的指定的情況下:

通過瀏覽器瀏覽,也就是作為web server瀏覽的情況下,檔案啟動並執行目錄是基於web server配置的

而通過命令列,則是基於系統內容path的

可以通過下面2個輸出看出不一樣
PHP code
echo getcwd();echo ini_get('include_path');
  • 聯繫我們

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