Students send their homework via a little html form. PHP writes their answers to a file. Sometimes they send the right answers, but then send again and the form is empty, or the answers are wrong.
The file names look like this: 1825010112_18BEwW4data (1825010112 is a student number, 18BE a class)
What I would like to do in php is, before I write the file:
- check if the file exists
- if it exists, append ‘_copy’ to the name and then write it.
The end of the php file looks like this:
$newname = $studentnr . "_18BEwW5data";
$path = "/home/myusername/public_html/18BE/php/uploads/";
$fp = fopen($path . $newname, 'w');
fwrite($fp, $body);
fclose($fp);
echo ' 成功! Your data has been saved 1 time in a text file! <br><br> ';
?>
Any tips please?