Is it possible to navigate back directories when specifying a path for file deletion in PHP?

When specifying a path for file deletion in PHP, it is not possible to navigate back directories using ".." as it may pose a security risk by allowing access to files outside the intended directory. To solve this issue, it is recommended to use absolute paths or define a base directory and concatenate the file path to it.

$baseDir = "/path/to/base/directory/";
$filePath = "subdirectory/file.txt";

$fullPath = $baseDir . $filePath;

if (file_exists($fullPath)) {
    unlink($fullPath);
    echo "File deleted successfully.";
} else {
    echo "File not found.";
}