【发布时间】:2017-05-17 04:37:27
【问题描述】:
我想在PHP 中读写.txt 文件,我已经可以使用读取文件了
$Readfile = fopen("file.txt", "r") or exit("Unable to open file!");
由于我想覆盖文件,所以我建议使用
$Readfile = fopen("file.txt", "r+") or exit("Unable to open file!");
但总是得到“无法打开文件!”我也尝试过使用w+ 之类的其他方法,但仍然没有给出任何结果。这里是我的代码的一些更新
<?php
//$Readfile = fopen("pengumuman.txt","r") or exit("Unable to open file!");
$Readfile = file_get_contents("pengumuman.txt");
if (isset($_POST["btnSimpan"])) {
$pengumuman = $_POST["pengumuman"];
fwrite($Readfile, $pengumuman);
}
?>
<textarea class="span12" style="min-height: 200px; height: auto;" name="pengumuman">
<?php
while(!feof($Readfile)) {
echo fgets( $Readfile);
}
?>
我试过file_get_contents,但它给了我一个很长的加载和空白文本区域
【问题讨论】: