haaglin Posted November 26, 2006 Share Posted November 26, 2006 HiIs 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,AllowDeny 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] Quote Link to comment https://forums.phpfreaks.com/topic/28528-solved-need-help-with-htaccess/ Share on other sites More sharing options...
theironchef Posted November 26, 2006 Share Posted November 26, 2006 actually can you explain that a little... i want to do the exact same thing... Quote Link to comment https://forums.phpfreaks.com/topic/28528-solved-need-help-with-htaccess/#findComment-130561 Share on other sites More sharing options...
haaglin Posted November 26, 2006 Author Share Posted November 26, 2006 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,AllowDeny from All</Files>[/code]And i made a phpscript to send users the file: [code]<?phpheader('Content-Type: application/octet-stream');header('Content-Disposition: attachment; filename="'.$_POST['file'].'.bkp"'); //filename i want them to seeheader('Content-Transfer-Encoding: binary');readfile("backups/".$_POST['file'].".bkp"); //path to the file you want them to download. ?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28528-solved-need-help-with-htaccess/#findComment-130605 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.