How to let users with required permission download a file via php?

Posted by Yegor on Stack Overflow See other posts from Stack Overflow or by Yegor
Published on 2010-06-09T22:21:40Z Indexed on 2010/06/09 22:32 UTC
Read the original article Hit count: 167

Filed under:
|
|

I have a php file that acts as a gatekeeper for all the files I want people to download, who ahve sufficient privilages.

The code I use throw the file to the user is

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=\"".$public_filename."\""); 
header("Content-Transfer-Encoding: Binary"); 
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header("Content-length: ".$f_filesize); 
readfile($file_path);

Most files are fairly large.... 400mb-10GB.

What would be a good way to do this, and keep the true locations + filenames secret, so people cant just link to the files directly, but HAVE to link thru my download.php?file=ID gatekeeper?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about readfile