How can including files from different directories impact the ability to write to a log file in PHP?

Including files from different directories can impact the ability to write to a log file in PHP if the file paths are not correctly specified. To solve this issue, you can use the `__DIR__` magic constant to get the absolute path of the current file and then construct the correct path to the log file based on that.

<?php
// Get the absolute path of the current file
$currentDir = __DIR__;

// Specify the path to the log file relative to the current file
$logFilePath = $currentDir . '/logs/log.txt';

// Write to the log file
$logMessage = "Log message here";
file_put_contents($logFilePath, $logMessage, FILE_APPEND);
?>