PHP to download any type of files like browser download

by Subramanian 2013-06-17 10:58:34

PHP to download any type of files like browser download

The Following php code is used to download any type of files i browser download panel.

$file = 'tect-GvSubhu.txt';

if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>


The $file is for which file you want to download in browser. just pass the correct file path to this variable.
679
like
0
dislike
0
mail
flag

You must LOGIN to add comments