簡體   English   中英

PHP的require()不適用於相對或完整

[英]php require() does not work with relative or full

我的require()命令有一個怪異的問題,它根本不起作用,給我一個怪異的錯誤。是的,我100%肯定我使用相對和完整路徑以及使用了正確的路徑include()include_once()require()require_once()但無濟於事。我測試了文件的存在並且它確實存在..對我來說這沒有意義! 我在論壇上沒有看到其他人遇到過與此相同的問題,我也嘗試過使用$_SERVER["DOCUMENT_ROOT"]類的全局變量和其他路徑,但這對我仍然不起作用。

過程是:HTML按鈕-> ajax調用“ addcomments.php”->頁面需要“ ajax.php”->錯誤

addcomments.php頁面:

//set path
$path = "g:/appserv/www/y4project/scripts/php/funcs/";

//check directory 
print_r(scandir($path));

//check if php file exists
if(file_exists($path."ajax.php"))
    echo "######### IT EXISTS!!! ##########";
else echo "@@@@@@ NO! @@@@@@@@";

//require it
require($path."ajax.php");

錯誤:

Array ( 
    [0] => . 
    [1] => .. 
    [2] => account.php 
    [3] => ajax.php 
    [4] => main.php 
    [5] => service.php ) 

######### IT EXISTS!!! ##########

Warning: require(1) [function.require]: failed to open stream: No such file or directory in G:\AppServ\www\y4project\scripts\AJAX\addcomments.php on line 10

Fatal error: require() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in G:\AppServ\www\y4project\scripts\AJAX\addcomments.php on line 10

我也嘗試過相對路徑,例如“ ../php/funcs/ajax.php”,同樣的問題。scandir scandir()file_exists()都找到了,但是require()失敗了!

非常感謝您的幫助!

編輯

我只是對其進行了測試,以確保可以從其他測試頁面中使用它,並且使用了一個函數並且可以正常工作,但是仍然無法通過AJAX調用的“ addcomments.php”頁面正常工作。

另一個編輯

我還檢查了PHP的文件require_once()require() ,但仍然看不到問題!

可能是某種路徑錯誤,還是一種安全措施,使得稱為腳本的AJAX無法如此調用其他腳本? 但這沒有意義嗎?
我也沒有在文檔中閱讀有關該內容的任何內容。
我什至嘗試要求HTML頁面,但仍然無法正常工作。

我迷路了..

您可以嘗試使用這種方式:

require dirname(__DIR__) . "/php/funcs/ajax.php";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM