What potential pitfalls should be considered when deleting a file based on a selection from a pulldown menu in PHP?

When deleting a file based on a selection from a pulldown menu in PHP, potential pitfalls to consider include ensuring that the selected file actually exists before attempting to delete it, verifying that the user has the necessary permissions to delete the file, and sanitizing the input to prevent any malicious file deletions.

<?php
// Check if the file exists before attempting to delete it
$selectedFile = $_POST['file'];
if (file_exists($selectedFile)) {
    // Verify user permissions before deleting the file
    if (is_writable($selectedFile)) {
        // Sanitize the file path to prevent any malicious deletions
        $safeFilePath = realpath($selectedFile);
        unlink($safeFilePath);
        echo "File deleted successfully.";
    } else {
        echo "You do not have permission to delete this file.";
    }
} else {
    echo "File does not exist.";
}
?>