How can the PHP script be improved to allow for proper navigation back to the parent directory (..) without causing path errors?

When navigating back to the parent directory (..) in a PHP script, it's important to handle the path correctly to avoid errors. One way to improve this is by using the realpath() function in PHP to get the absolute path of the parent directory. This ensures that the path is resolved correctly regardless of the current working directory.

// Get the absolute path of the parent directory
$parentDirectory = realpath(dirname(__FILE__) . '/..');

// Use the $parentDirectory variable in your code for proper navigation
echo "<a href='$parentDirectory'>Go to Parent Directory</a>";