How can PHP be used to pass a file name from one page to another for deletion?

To pass a file name from one page to another for deletion in PHP, you can use query parameters in the URL. Simply append the file name as a query parameter in the URL of the link that leads to the deletion page. Then, on the deletion page, retrieve the file name from the query parameter and use it to delete the corresponding file.

// On the page where the file name is passed
$fileToDelete = 'example.txt';
<a href="delete.php?file=<?php echo $fileToDelete; ?>">Delete File</a>

// On the deletion page (delete.php)
if(isset($_GET['file'])){
    $fileToDelete = $_GET['file'];
    unlink($fileToDelete);
    echo "File $fileToDelete has been deleted.";
} else {
    echo "No file specified for deletion.";
}