[英]apache php javascript - Failed to open stream: No such file or directory in /var/www/html/bla
我希望有一些火花可以幫助我。 我在apache網路伺服器(Raspberry Pi 2)上建立了一個網站。 我正在用php編碼網站。
Index.php
有一個div,可以使用我編寫的簡單jQuery腳本進行刷新。
Index.php
包括/include/start/times.php
times.php
包含/functions/time_func.php,該函數調用一個函數來顯示index.php div中的實時時間。
jQuery每10秒刷新一次。
首次加載頁面時,div正確顯示。 當jQuery在10秒后運行時,div中的標題中將顯示錯誤。 我也在下面收到此錯誤:
Warning: include(): Failed opening 'functions/times.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
我查看了服務器權限以及其他所有我能想到的內容。 我希望有人可以幫助我,這現在讓我非常沮喪。
有趣的是,如果我將所有相關文件轉儲到我的網站根目錄中,並修改包含路徑,則一切正常:-/
以下是一些文件內容:
index.php:
<html>
<head lang="en">
<meta charset="UTF-8">
<link href="css/style.css" rel="stylesheet">
<script src="js/jquery-2.1.3.min.js"></script>
<script>
function updateLeft() {
var url = "include/start/times.php";
jQuery("#left").load(url);
}
setInterval("updateLeft()", 5000);
</script>
</head>
<body style="overflow-y: hidden;">
<?php
include 'include/start/times.php';
?>
</body>
</html>
times.php:
<div id="left">
<p class="no-margin text-shadow">Times: <br><br><span class="text-bold" id="pressure">
<?php
include 'functions/time_func.php';
times();
?>
</span></p>
</div>
time_func.php:
<?php
// Define the cURL function
function curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20160904 Firefox/4");
$page = curl_exec($ch);
curl_close($ch);
return $page;
}
function times(){
$x_data = curl("http://mysite.james.com/test_sceh.html");
$doc = new DOMDocument();
$doc->loadHTML($x_data);
$sec1 = $doc->getElementsByTagName('td')->item(0);
$time1 = $doc->getElementsByTagName('td')->item(4);
$sec2 = $doc->getElementsByTagName('td')->item(6);
$time2 = $doc->getElementsByTagName('td')->item(10);
$sec3 = $doc->getElementsByTagName('td')->item(12);
$time3 = $doc->getElementsByTagName('td')->item(16);
$xtime = $sec1->nodeValue . ' - ' . $time1->nodeValue . '<br>' . $sec2->nodeValue . ' - ' . $time2->nodeValue . '<br>' . $sec3->nodeValue . ' - ' . $time3->nodeValue . '<br>';
print_r($xtime);
}
?>
發生這種情況是因為路徑無法以相同的方式解析。
當您第一次加載頁面時,所有內容均從index.php
開始,我猜“功能”與“ include
”處於同一級別
當包含路徑是相對的時,它們是相對於祖先的。 因此,當您加載頁面時,相對於index.php
,但是當您執行ajax請求時,相對於times.php
。
由於functions
不是include/start
的子文件夾,因此無法找到time_func.php
對於這種情況,其中不同父文件夾中包含相同文件,則應使用絕對路徑。
就像是:
<?php include $_SERVER['DOCUMENT_ROOT'].'/include/start/times.php'; ?>
和
<?php include $_SERVER['DOCUMENT_ROOT'].'/functions/time_func.php'; ?>
或者,當然,不要更改您在var url
使用的相對路徑,它需要相對於主機名的根保持相對。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.