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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.