I wrote the function below as part of a larger class.
The fopen stage works, and, as according to the documentation at
www.php.net/fopen that succesfully creates a new file.
The fwrite stage returns false, however, on the first time the function is
run, but returns true the second time it is run.
Can anyone suggest why fwrite only works the second time?
There are no entries in the apache log, even with error reporting fully
turned up (note that I have removed @ from infront of each function, so
would expect something).
---
function writeDataToFile ($data, $file) {
# Attempt to open the file in read+write mode
if (!$fileHandle = fopen ($file, 'a+b')) {return false;} else {
# Attempt to write the data
#!# For some reason this returns false just after the first time trying to create the file
if (!fwrite ($fileHandle, $data)) {return false;} else {
# Having written to the file, close it
fclose ($fileHandle);
# Return a positive result
return true;
}
}
}
---
Martin Lucas-Smith
www.geog.cam.ac.uk/~mvl22 www.lucas-smith.co.uk