Enter your keyword

Download Files in PHP

To downloads files in the php you need to use below code. just replace your file name with  akashwagh.pdf file

[php]
<?php
$filename = ‘akashwagh.pdf’;

$ctype="application/[extension]";

// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");

// change, added quotes to allow spaces in filenames

header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));

readfile("$filename");

exit();

?>[/php]

No Comments

Leave a Reply

Show Buttons
Hide Buttons