Tutorialsplane

Php Force to download a file


Php Force to download a file : Sometimes we need to download file forcefully. Here in this tutorial we are going to explain how you can force browser to download the files.


Php Force to download a file

You can use below method to download a file in php as below –

Php Force to download a file Example:

$file = "http://testdomain.com/file.exe"; 
header("Content-Description: File Transfer"); 
header("Content-Type: application/octet-stream"); 
header("Content-Disposition: attachment; filename=\"$file\""); 
readfile ($file); 

The above example will download the file from the specified location.