How can the unlink() function be used to delete images from a directory in PHP?

To delete images from a directory in PHP, you can use the unlink() function. This function takes the file path as an argument and deletes the file from the server. You can loop through the list of images in the directory and call unlink() on each file to delete them.

$directory = "path/to/images/";

$files = glob($directory . "*");

foreach($files as $file){
    if(is_file($file)){
        unlink($file);
    }
}