The subject pretty much sums it up. I've written a script to create a file and chmod to 0777. Then the script writes data to the new file. When I call it from my browser it works. When I call it from Cron, it creates the file and chmod's the file successfully. However it will not write any data to the file.
Is there something special that I should be doing? Here is the code I am using to write to the file:
$filename = $userid.'.txt';
$content = "<center>Hello World.\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
print "Cannot open file ($filename)";
exit;
}
if (!fwrite($handle, $content)) {
print "Cannot write to file ($filename)";
exit;
}
print "Success, wrote ($content) to file ($filename)";
fclose($handle);
} else {
print "The file $filename is not writable";
}
As previously stated, this code works when called from my browser, but fails when called from Cron.
Any ideas why? 😕
Thanks