I have a page with links on it for files to download. The link points to a page called dl.php which contains the following code:

$file = "manuals/".$_POST['file'];
header('Content-Description: File Transfer'); 
header('Content-Type: application/pdf'); 
header('Content-Length: ' . filesize($file)); 
// to download 
header('Content-Disposition: attachment; filename=' . basename($file)); 
// to open in browser 
//header('Content-Disposition: inline; filename=' . basename($file)); 
readfile($file);

For the most part everything is fine. But I notice that people with slower internet connections often have a hard time downloading the file simply because some files are very large.

So I thought of having a Lite Download Manager that they could install and use. But I noticed that download manager try and download the page dl.php instead of the actual file. How do I work around this.

I cannot have them access the file directly as some of the information is confidential. I really need to monitor the downloads.

Thanks in advance

    You could set the header Content type to be "octet-stream" and then echo the file-contents instead of attaching it. But, if you're giving PDF's, then others will open them in the browser. So the alternative is to have your DL manager use dl2.php which will output the documents to the browser (as inline) and then the user will download them as usual. Otherwise, people use dl.php 😉

      Write a Reply...