2012-09-16 109 views
3

我有一個文件Profile.php其中包括Profile_Control.phpprofile_control包括Profile_Model.php。每件事情都很好,直到這裏。無法打開流沒有這樣的文件或目錄。 php

我有另一個腳本名爲Upload.php從中上傳數據。這upload.php的還包括Profile_Control.php,正如你知道Profile_Control包括Profile_Model.php。現在我不知道它爲什麼做出這樣的error.When的Profile.php負載正常工作,但是當我上傳的數據,它說

Warning: include(../Model/Profile_Model.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\php\gagster\Control\Profile_Control.php on line 4 

在upload.php的:

include_once("../../Control/Profile_Control.php"); 

在Profile.php:

include_once("../Control/Profile_Control.php"); 

在Profile_Control.php:

include_once("../Model/Profile_Model.php"); 

文檔結構:

+-Control/ 
| |  
| +---- Profile_Control.php 
| 
+-Model/ 
| | 
| +---- Profile_Model.php 
| 
+-Other/ 
    | 
    +-- Upload/ 
      | 
      +---- Upload.php 
+0

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

+0

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

回答

1

你可以使用PHP file_exists()功能,以確保文件包含如果不是做你的東西

if (file_exists($filename)) { 
    echo "The file $filename exists"; 
} else { 
    echo "The file $filename does not exist"; 
} 

,並使用

defined('root') ? null : define('root', "url of your site " ); 

include_once(root."rest of address"); 
+0

是的 - 這會產生一個錯誤,但你並沒有試圖回答實際的問題。 – Lix

+0

@Lix看起來像編輯的實際問題 –

+0

@Lix我認爲現在它會幫助用戶 –

8

而是使用相對路徑(../),你爲什麼不試着給相對於你的$_SERVER['DOCUMENT_ROOT']位置的絕對路徑。我通常會定義一個常數,以幫助可讀性 -

define('_root',$_SERVER['DOCUMENT_ROOT']); 

include(_root.'/Control/Profile_Control.php'); 

現在,您可以將相同的代碼行中的每個文件要包括在Profile_Control.php

user1280616也使得一個有效的點關於測試在包含它之前存在一個文件。也許你應該考慮實施。

+0

雖然答案標記在正確的是有幫助的,我必須說這是這個答案,解決了我的問題。我嘗試了絕對路徑和相對路徑,都沒有首先獲取文檔根目錄並在路徑中使用它。 – vmex151

+0

現在有這種頻繁的錯誤排查清單在這裏:https://stackoverflow.com/a/36577021/2873507 –

相關問題