[英]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.