I am experiencing a weird issue that I can't explain, hoping you can help me with this.
I am writing the contents of a form to a file like this:
$data = stripslashes($_POST['data']);
// create external data file
$file = fopen($filepath, 'w+') or die("ERROR: Can't create/edit file. Check permissions!");
fwrite($file, $data);
chmod($filepath,0666);
fclose($file);
// create external data file backup
$file = fopen($filepath.'.bak', 'w+') or die("ERROR: Can't create/edit backup file. Check permissions!");
fwrite($file, $data);
chmod($filepath,0666);
fclose($file);
As you can see the two sections of the code are identical (except for the addition of the "bak" extension for the backup file) however the two files that are generated are different...
The first file contains an extra empty line after every existing line, while the second file (the backup one) contains exactly what is sent in the $data variable via post...
How is this possible? I can't explain it.
Any ideas?
Thanks