Why is it important to always work with absolute file paths in PHP when deleting files?

When deleting files in PHP, it is important to always use absolute file paths to ensure that the correct file is being deleted. Using relative paths can lead to deleting unintended files or even system files if not careful. Absolute paths provide a clear and specific reference to the file location, reducing the risk of errors.

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