I have a web form and i want to get the data from the user and write it to a text file on the server but i need the server to create a new text file with a random name each time something is entered into the form.
So far i have this but it wont make a random file each time.
<?php
if(isset($_POST['field1']) && isset($_POST['field2'])) {
$data = $_POST['field1'] . '-' . $_POST['field2'] . "
";
$file = rand(0000,9999);
$ret = file_put_contents('/messages/$file.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');
}
?>