File_put_contents returns true, but file doesn't write either.

I have a small PHP script that runs when I click a button on some HTML page:

<?php
if(isset($_POST['field1'])) {
    $data = $_POST['field1'] . "\n";
    $ret = file_put_contents('/tmp/mydata.txt', $data, FILE_APPEND | LOCK_EX);
    if($ret === false) {
        die('There was an error writing this file');
    }
    else {
        echo "$ret bytes written to file";
    }
}
else {
   die('no post data to process');
}

      

When I give html some text and run the script, I get an echo:

16 bytes written to file

However, when I then open the file, it is empty and reads as "zero bytes" in size.

I tried communicating with permissions and checking the log files without prompts, I made sure the private text gets to the php script. I'm completely stumped, any suggestions?

+3
html php file-put-contents


source to share


No one has answered this question yet

Check out similar questions:

691
How to get (extract) file extension in PHP?
4
FormData object is always empty
2
PHP file_get_contents () sometimes returns null bytes / false
1
How do I make my html <select> sticky with php?
0
PHP5 $ _SESSION not working and register_globals disabled
0
Base64_decoded image string stored in directory does not display image
0
Jquery ajax message not working
0
FILE_APPEND does not work as expected with file_put_contents
0
file_put_contents is an empty file?
0
Can you read the file while writing to the file using file_put_contents?



All Articles
Loading...
X
Show
Funny
Dev
Pics