What is the potential risk of deleting files using URLs in PHP scripts?

The potential risk of deleting files using URLs in PHP scripts is that it can lead to security vulnerabilities such as allowing unauthorized users to delete important files on the server. To mitigate this risk, it is recommended to validate user input and ensure that only authorized users have the permission to delete files.

<?php
// Validate user input before deleting files
if(isset($_GET['file'])) {
    $file = $_GET['file'];
    
    // Check if user is authorized to delete the file
    if($userIsAuthorized) {
        unlink($file);
        echo "File deleted successfully";
    } else {
        echo "You are not authorized to delete this file";
    }
} else {
    echo "File parameter is missing";
}
?>