How can PHP be used to create a download link for files on a server?

To create a download link for files on a server using PHP, you can use the header() function to set the appropriate content type and disposition for the file. You also need to specify the file path and name in the href attribute of the anchor tag.

<?php
$file = 'path/to/your/file.pdf';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=' . basename($file));
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
} else {
    echo 'File not found';
}
?>