PHP Header() Function - Force header for a file to download in PHP

This either in PHP will help you to sends the files:
<?php

$file 
'folder/yourfile.zip' //Any file *.*

if (! file) {
    die(
'file not found'); //Or do something 
} else {
    
// Set headers
    
header("Cache-Control: public");
    
header("Content-Description: File Transfer");
    
header("Content-Disposition: attachment; filename=$file");
    
header("Content-Type: application/octet-stream");
    
header("Content-Transfer-Encoding: binary");
    
// Read the file from disk
    
readfile($file); 
}

?>
Share this