linux - PHP fwrite doesn't update the file using the append mode -
the following code working doesn't update contents of file created.
i can see file contents have changed (the size increased) when download file server it's empty. file chmod 666 , parent directory well.
its linux server running apache , php. i've tried using fflush force flush contents.
<?php header("location: http://www.example.com"); $handle = fopen("log.txt", "a"); foreach($_post $variable => $value) { fwrite($handle, $variable); fwrite($handle, '='); fwrite($handle, $value); fwrite($handle, '\r\n'); } fwrite($handle, '\r\n'); fflush($handle); fclose($handle); ?>
what problem?
thanks!
i think practice check if file writable is_writable
if can opened checking value returned fopen
, way code right.
try this:
$filename = "log.txt"; $mode = "a"; // let's make sure file exists , writable first. if (is_writable($filename)) { // in our example we're opening $filename in append mode. // file pointer @ bottom of file hence // that's $somecontent go when fwrite() it. if (!$handle = fopen($filename, $mode)) { echo "cannot open file ($filename)"; exit; } foreach($_post $variable => $value) { fwrite($handle, $variable); fwrite($handle, '='); fwrite($handle, $value); fwrite($handle, '\r\n'); } fwrite($handle, '\r\n'); fflush($handle); fclose($handle); echo "content written file ($filename)"; } else { echo "the file $filename not writable"; }
Comments
Post a Comment