gpt4 book ai didi

php - 无法在php中写入txt文件

转载 作者:太空宇宙 更新时间:2023-11-04 05:22:15 25 4
gpt4 key购买 nike

我试图用 PHP 文本框中输入的数字简单地覆盖 txt 文件。 PHP 和文本文件都位于我的 apache2 服务器的 html 目录中。每次执行时它只显示 die() 字符串。我也尝试使用 fwrite() 得到相同的结果。任何帮助将非常感激。

<HTML>
<TITLE>Home Automation Interface</TITLE>
<BODY>
<H1>Air Conditioning Power(Relay 1)</H1>
<H2>Turn AC On/Off</H2>
<H3>
<p>
<form action="relayToggle.php" method="get">
<input type="submit" value="AC Power">
</form>
</p>
<form method= "post" action = "homeInter.php">
<p>
<label for="acTemp">AC temperature (F):</label><br/>
<input type="text" id="temp" name="temp">
</p>
<button type="submit" name="submit" value="send">Change Temperature</button>
</form>
<p><strong>
<?php

$temp= $_POST['temp'];
echo $temp;
file_put_contents("/var/www/html/temp.txt", (string)$temp) or die("Unable to open file!");
?>
}
}
?>
</strong>
</p>
</H3>
</BODY>
</HTML>

最佳答案

将您的 PHP 代码包装在有效的检查器中以查看表单是否已提交

像这样:

if ($_POST):
//All functions go here
endif;

如果该文件与您的 PHP 文件位于同一目录中,只需将目录更改为 file_put_content() 中的文件名.file 扩展名

关于php - 无法在php中写入txt文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39924220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com