What are the potential pitfalls of using relative paths in PHP functions like unlink()?

Using relative paths in PHP functions like unlink() can be risky because the path resolution is based on the current working directory of the script, which may not always be predictable. This can lead to unintended file deletions or errors if the script is run from a different location than expected. To avoid this issue, it's recommended to use absolute paths instead, which provide a fixed reference to the file regardless of the script's current working directory.

$file_path = '/path/to/file.txt';
if (file_exists($file_path)) {
    unlink($file_path);
    echo 'File deleted successfully.';
} else {
    echo 'File not found.';
}