It turns out that running the following PHP page does write and save to the file:
<?php
function log( $msgs ) {
$filepath = "log.txt";
$lineBreaks = PHP_EOL . PHP_EOL;
$file = fopen( $filepath, "c" );
foreach( $msgs as $msg ) {
fwrite( $file, $msg . $lineBreaks );
}
fclose( $file );
}
log( array( 'Hi there!', 'This is a message.' ) );
?>
But when I paste this function into my WordPress plugin, it says permission denied. Why?