使用的fopen時,我想讀&寫.txt
文件中PHP
什麼,我已經可以讀取使用不能使用「+」在PHP
$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
,但它給了我很長的加載和空白文本區域
我可以直接將它們保存爲.txt文件嗎? –
@AndreasChandraGaozu是的,我已經給出了編寫文件的說明。檢查更新的答案? –
@AndreasChandraGaozu你能用簡單的話來說,你想做什麼? –