Download in PHP
file_download.php:
<?php
$cmd = $_REQUEST['cmd'];
switch($cmd)
{
case ‘download’: header(“Content-type:application/pdf”);
header(“Content-Disposition:attachment;filename=downloaded.pdf”);
// Put the source in the root directory.if you don’t then change the path accordingly.
readfile(“php5_power_programming.pdf”);
break;
default : break;
}
?>
Client side:
Simply call the above script according to the following way:
<a href=”/file_download.php?cmd=’download’ “>download</a> or the you can do it with a little bit help of javascript.
that’s enough.Very simple.Isn’t it?
