How can I trigger a file download (.exe) automatically when a user clicks on an input button in PHP?

To trigger a file download (.exe) automatically when a user clicks on an input button in PHP, you can use the header() function to set the appropriate content type and attachment disposition. You will also need to specify the file path to the .exe file that you want the user to download. This will force the browser to download the file when the button is clicked.

<?php
if(isset($_POST['download'])) {
    $file = 'path/to/your/file.exe';
    
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Content-Length: ' . filesize($file));
    
    readfile($file);
    exit;
}
?>

<form method="post">
    <input type="submit" name="download" value="Download .exe file">
</form>