I have a small PHP script being run when I press 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 the html some text and run the script I get an echo:
16 bytes written to file
However when I then go to open the file, it's empty, and reads as 'zero bytes' in size.
I've tried messing with permissions and checked the log files with no hints, I've made sure the cirrect text is getting to the php script. I'm totally stumped, any suggestions?