Welcome Guest, Not a member yet? Register   Sign In
Force download file in php
#1

[eluser]Unknown[/eluser]
Hi,

I want to restrict access to specific folder if some one copies and paste download file link or folder in browser. For that i have modified my htaccess file and added following lines of codes in that

RewriteEngine On
RewriteCond %{REQUEST_URI} \.(doc|zip|pdf)$ [NC]
RewriteRule ^(.*)$ /download-pdf.php?filename=$1 [L]

Beside this i have placed plenty of codes searcher from google to make it accessible when accessed from my domainsite.com

http://stackoverflow.com/questions/1962 ... row-script

http://stackoverflow.com/questions/1365 ... rowser-url

and searched almost every site. But restricting access to my files will not allow me to access it through my site also.

The only solution i came across is to force download the restricted file if accessed through my site. For that i have made forcedownload.php file and reading the contents of file in that. But the problem is that how to add condition in htaccess to go to download page if accessed through my site. Any help??
#2

[eluser]Unknown[/eluser]
Hi there,

I had a look at your post, if I understand you correctly, you are only want people to be able to download files from your domain only?

In your file download controller add some sort of validation like:

Code:
if ($this->agent->is_referral() == TRUE)
{
   // error function
}
else
{
  // download the file
}

Returns TRUE/FALSE (boolean) if the user agent was referred from another site.
User Guide – User Agent Class

Other ideas:


Thinking aloud, what you are trying to achieve sound similar to hotlinking prevention. I found a Ci orientated hotlinking article which could help:

htaccess hotlinking
#3

[eluser]InsiteFX[/eluser]
Code:
Order Allow,Deny
Allow from 192.168.0  ## Change to your host ip




Theme © iAndrew 2016 - Forum software by © MyBB