2011-12-31 85 views
4

我在HTML中編寫了一個網站,但我想在一個文件中的標題和導航欄部分,所以我只需要更改一次。我將所有頁面改爲.php並添加了php包含。但是,現在我在我放入文件夾的頁面上出現錯誤,因此我可以創建無格式鏈接。PHP包括 - 未能打開流:沒有這樣的文件

頭文件:/test/assets/header.php

作品:/test/index.php包含<?php include 'assets/header.php'; ?>

拋出錯誤:/test/company/index.php包含<?php include '/test/assets/header.php'; ?>

錯誤:

Warning: include(/test/assets/header.php) [function.include]: failed to open stream: No such file or directory 

Warning: include() [function.include]: Failed opening '/test/assets/header.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') 

我有鏈接到頭文件中的問題即位於根文件夾中的文件夾中。我相信這是一個簡單的問題,只是不知道如何輸入URL。如果我嘗試包括完整路徑header.php中我得到了URL file-access is disabled錯誤

+0

經常遇到此錯誤,並快速排除故障,請按照下列步驟操作:https://stackoverflow.com/a/36577021/2873507 – 2016-04-12 15:37:03

+0

可能重複的[無法打開流:沒有這樣的文件或目錄]( http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – 2016-09-10 09:20:48

回答

10

如果您使用/開始路徑,那麼它是絕對路徑。絕對主管到實際的文件系統根目錄,而不是虛擬的document root。這就是它失敗的原因。

通常,這是什麼意思:

include "$_SERVER[DOCUMENT_ROOT]/test/assets/header.php"; 
// Note: array key quotes only absent in double quotes context 
+0

此處有一個此常見錯誤的故障排除清單:https://stackoverflow.com/a/36577021/2873507 – 2016-04-12 15:37:17

0

不是一個URL;它是一個文件路徑(儘管您可以使用使用完整服務器配置允許它的URL)。

+0

現在有一個這裏的頻繁錯誤的故障排除清單:https://stackoverflow.com/a/36577021/2873507 – 2016-04-12 15:37:30

4

我也面臨着同樣的警告:

Warning: include(/test/assets/header.php) [function.include]: failed to open stream: No such file or directory 
Warning: include() [function.include]: Failed opening '/test/assets/header.php' for inclusion (include_path='.:/usr/local/lib/php:/usr/local/php5/lib/pear') 

我解決了他們與以下解決方案:

你必須定義你的然後使用包含功能如下:

define('DOC_ROOT_PATH', $_SERVER['DOCUMENT_ROOT'].'/'); 
require DOC_ROOT_PATH . "../includes/pagedresults.php"; 

之後,您可以使用任何目錄結構。

+0

'注意:使用未定義的常量DOC_ROOT_PATH - 假定爲'DOC_ROOT_PATH'' * *使用'DOC_ROOT_PATH'替代''DOC_ROOT_PATH'' ** – Elshan 2015-03-21 23:19:40

+0

現在有一個t檢查清單他在這裏頻繁的錯誤:https://stackoverflow.com/a/36577021/2873507 – 2016-04-12 15:37:24

相關問題