Php code to download pdf file from server not working
<p>I have written a code to download pdf file from server, but the code is not working and I cant even see the errors
This is the code which I am using.
    

<pre><code>// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/product_images/"; // change the path to fit your     websites document structure
fullPath = $path.$_REQUEST['download_file'];

if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
    case "pdf":
    header("Content-type: application/pdf"); // add here more headers for diff.     extensions
    header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");     // use 'attachment' to force a download
    break;
    default;
    header("Content-type: application/octet-stream");
    header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
    $buffer = fread($fd, 2048);
    echo $buffer;
}
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
// &lt;a href="download.php?download_file=some_file.pdf"&gt;Download here&lt;/a&gt;
?&gt;
</code></pre>

<p>I am fetching the file from database and this is my download link which I am using on my site</p>

<pre><code>&lt;div style="padding-left:320px; padding-top:5px;"&gt;&lt;a href="&lt;?php echo URL ?&gt;download.php?download_file=&lt;?php echo $prod_details['specification_pdf']?&gt;"&gt;
&lt;img src="&lt;?php       echo URL ?&gt;images/download_pdf.png" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Can anyone please help me in resolving this problem</p>
