Re: Advice on maintaining public and private files
| From: | Nathan Rixham | Date: | Sat, 20 Feb 2010 16:20:15 +0000 |
| Subject: | Re: Advice on maintaining public and private files | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-302239@lists.php.net to get a copy of this message | ||
Kim Madsen wrote:
> Michael Stroh wrote on 19/02/2010 19:19:
>> I have a site I'm working on with some data that I want to be
>> readable by anyone, but some files that I want to keep hidden from
>> outside users. Here is an example of my file structure.
>>
>> /products/data1/item_1/data.txt
>> /products/data2/item_2/data.txt
>
> since no one has suggested it then... if you're on an Apache webserver
> use a .htaccess file in data2 which contains:
>
> Deny from all
> Allow from none
>
> That will do the trick and PHP can still fetch the files in data2 and
> serve it to the user.
>
Glad you said this; I'd been waiting to see if anybody would - certainly
there is no quicker or easier way to solve this particular problem.
Also worth adding that you can easily password protect the directories
too using HTTP authorisation [1] (and even hook it in to LDAP or
suchlike very simply).
It's the curse of the PHP developer to try and use PHP to solve every
problem - we all fall fowl of it often (I've wasted years doing things
in PHP that really should have been done with a different tech).
[1] http://httpd.apache.org/docs/2.0/howto/auth.html
Regards!
Nathan