dpymrcl269187540 2015-10-28 06:27
浏览 4

窗口打开时停止在php中重写

I have a popup window that opens when I want a person to fill in a textbox. The textbox is then transferred to a .txt file on the server. My problem is that once the popup window is opened, the text on the .txt file is overwritten as a blank file until the user adds their own text.

I would like to figure out what I'm doing wrong or try to find a way to correct this issue.

This is my php:

<?php
date_default_timezone_set('DST');

// Open the text file and prepare to write (will be blank if no text is entered.)
$f = fopen("blog.txt", "w");

// Write text
fwrite($f, $_POST["textblock"] . " -- " . date("l jS \of F Y", time()) . " "); 

// Close the text file
fclose($f);

?>

How do I prevent it from blanking out when I open the blog.txt file? I'd like to keep the text that was on there before a rewrite.

  • 写回答

2条回答 默认 最新

  • douduiwei2831 2015-10-28 06:41
    关注

    what is happening your case is that you are overwrite old file and create new file.if you want to append new text to the file without losing old data follow the example below :

    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    $stringData = "Your new data 
    ";
    fwrite($fh, $stringData);
    fclose($fh);
    
    评论

报告相同问题?