Jump to content

[solved] Need help with .htaccess


haaglin

Recommended Posts

Hi

Is there a way i can prevent direct access to files, unless they have been refered by my php script?
I have a backup directory, that have a file "1164554281.bkp". I want to deny people to type the address to the file, but if my php script redirects them to it, then they are allowed to download it.

update:
Sorry, Solved it 5 minutes after i posted.
i made a htacces with this:
[code]<Files *.bkp>
Order Deny,Allow
Deny from All
</Files>[/code]

and in the php fil i used this:
[code]
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$_POST['file'].'.bkp"');
header('Content-Transfer-Encoding: binary');
readfile("backups/".$_POST['file'].".bkp");[/code]
Link to comment
https://forums.phpfreaks.com/topic/28528-solved-need-help-with-htaccess/
Share on other sites

Sure. i made a .htaccess file in the backup folder with this in it (change *.bkp to the filetype you want):
[code]<Files *.bkp>
Order Deny,Allow
Deny from All
</Files>[/code]

And i made a phpscript to send users the file:
[code]<?php
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.$_POST['file'].'.bkp"'); //filename i want them to see
header('Content-Transfer-Encoding: binary');
readfile("backups/".$_POST['file'].".bkp"); //path to the file you want them to download.
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.