Download a file in php

## Download file with a save option in php.

$filename  = "newfile.pdf";

$file_url  = $filepath.$filename;

//example: $file_url = 'http://www.link.com/file.pdf';

header('Content-Type: application/octet-stream');

header("Content-Transfer-Encoding: Binary"); 

header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 

readfile($file_url);

Leave a Comment