I have a set of tar.gz files inside a folder protected against http access via .htaccess. I wish to allow direct curl downloading of these files via http. I have done this to things like images by setting the header information to something like:
$file='/some/file/protected/by/htaccess.png';
header("Content-type: image/png");
readfile($file);
My question: Is there a way to provide direct access to these tar.gz files in a similar manner to the way I did it with images?
The reason I would like to do it in this way is that I would like to control access to which users can access these files by our site's login system.
Edit: as pointed out by Machavity, my code was pointing at a jpg, and had a png header.
For tar.gz
$filename = 'path/to/your/file.tar.gz';
header('Content-Type: application/x-compressed');
header("Cache-Control: no-store, no-cache");
header('Content-Disposition: attachment; filename="' . basename($filename) . '"');
header('Content-Length: ' . filesize($filename));
readfile($filename);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With