fwrite to txt-file

Posted by timkl on Stack Overflow See other posts from Stack Overflow or by timkl
Published on 2010-05-14T09:47:01Z Indexed on 2010/05/14 9:54 UTC
Read the original article Hit count: 323

Filed under:
|

I'm currently trying to write to a txt-file with PHP, I've found this small script:

<?php
$filename = 'testFile.txt';
$somecontent = "Add this to the file\n";

if (is_writable($filename)) {

    if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
    }

    if (fwrite($handle, $somecontent) === FALSE) {
        echo "Cannot write to file ($filename)";
        exit;
    }

    echo "Success, wrote ($somecontent) to file ($filename)";
    fclose($handle);

} 

else {
    echo "The file $filename is not writable";
}
?>

I get a success-message, but nothing is written to the file. Even if I delete the txt-file I still get the success-message

Does anybody know how to troubleshoot a situation like this?

© Stack Overflow or respective owner

Related posts about php

Related posts about fwrite