<html> <head></head> <body> <form name="form 1" method="post" action=""> <table> <tr> <td>留言板</td> <td><textarea name="LY" rows=8 cols=20></textarea></td> </tr> <tr> <td><input type="submit" name="b1" value="显示"></td> <td><input type="submit" name="b2" value="提交"></td> </tr> </table> </form> </body> </html> <?php $str=@$_POST["LY"]; $handle=fopen("E:\PHP2\phpnow\htdocs\1.txt","w+"); file_put_contents("E:\PHP2\phpnow\htdocs\1.txt",$str); $filename="E:\PHP2\phpnow\htdocs\1.txt"; $num=readfile($filename); fclose($handle); ?>
<html> <head></head> <body> <form name="form 1" method="post" action=""> <table> <tr> <td>留言板</td> <td><textarea name="LY" rows=8 cols=20></textarea></td> </tr> <tr> <td><input type="submit" name="b1" value="显示"></td> <td><input type="submit" name="b2" value="提交"></td> </tr> </table> </form> </body> </html> <?php $str=@$_POST["LY"]; $handle=fopen("E:\PHP2\phpnow\htdocs\1.txt","w+"); file_put_contents("E:\PHP2\phpnow\htdocs\1.txt",$str); $filename="E:\PHP2\phpnow\htdocs\1.txt"; $num=readfile($filename); fclose($handle); ?>
我觉得应该是锁的问题。在用fileput的时候,不需要打开文件了。
file_put_contents不需要fopen
fopen之后没有close,读写都会失败。
楼主的写法也实在太奇葩了,一般不可能会有这样的用法。
但纯就代码而言,我觉得1楼说的对,应该是个锁的问题,在FOPEN时,PHP程序就把文件锁定了,当然不可以再用file_put_contents写入文件内容了。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号