从html调用树莓派时,php脚本无法正常运行

时间:2020-04-23 11:10:43

标签: php html jquery linux raspberry-pi

我正在树莓派上创建网页

这是我的html代码的本质:


<html><head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    $(document).ready(function(){
        setInterval(function(){
        $("#test").load('climate.php') //load php result on the page
        }, 1000);
    });

</script>
</head>

<body data-gr-c-s-loaded="true">
    <div id="test"></div>
</body></html>

我想使用此php脚本从文本文件中包含一些数据:

<?php
    $filename = "/var/tmp/climate/save_climate.txt";
    if(file_exists($filename)){
      echo file_get_contents($filename);
    }
    else {
      echo 'could not find file'
    }
?>

我的html和php脚本运行良好,但是对文件的访问存在问题:

当我测试我的PHP脚本时,他找到了我的文件:

pi@raspberrypi:/var/www/HTML/home $ PHP climate.php
Temp=20.0*  Humidity=64.0%

但是在网页上,这不起作用:

显示

我的“找不到文件” 消息。

有人在解释这里发生的事情吗?

提前谢谢!

说明:

  • 我的php脚本和html都位于/ var / www / html / home

  • 文本文件位于/var/tmp/climate/save_climate.txt中。 cron每10分钟更新一次,这就是为什么他不在同一目录中。

  • 我的网站和php脚本运行良好,问题出在其他地方。

  • 我的网站位于本地网络上,完全由我的raspi托管。

  • 我正在使用raspbian Buster

0 个答案:

没有答案
相关问题