The answer is pretty simple, @Jon Stirling posted this when I was typing, but I will explain you a little more.
one puts your files outside your public html directory,
Configure E.gcpanel
user/public_html /public_html/download.php user/documents/ /documents/file.doc /documents/file.pdf
@dhh posted the base file download.php php, however, since you want to force your things to be downloaded, which you can do, for example, search and provide the correct mime type, this is an extension of its code to make the best use of 1 force downloading the file and 2 allowing different file types
download.php
//check users is loged in and valid for download if not redirect them out // YOU NEED TO ADD CODE HERE FOR THAT CHECK // array of support file types for download script and there mimetype $mimeTypes = array( 'doc' => 'application/msword', 'pdf' => 'application/pdf', ); // set the file here (best of using a $_GET[]) $file = "../documents/file.doc"; // gets the extension of the file to be loaded for searching array above $ext = explode('.', $file); $ext = end($ext); // gets the file name to send to the browser to force download of file $fileName = explode("/", $file); $fileName = end($fileName); // opens the file for reading and sends headers to browser $fp = fopen($file,"r") ; header("Content-Type: ".$mimeTypes[$ext]); header('Content-Disposition: attachment; filename="'.$fileName.'"'); // reads file and send the raw code to browser while (! feof($fp)) { $buff = fread($fp,4096); echo $buff; } // closes file after whe have finished reading it fclose($fp);
PS is a list of mime types for abig if you want to add support for other files http://www.hansenb.pdx.edu/DMKB/dict/tutorials/mime_typ.php
source share