Re: [PHP] Advice on maintaining public and private files

[email protected] (Al)
Newsgroups php.general
Message-ID <[email protected]>
I use Kim's solution and take it one step forward. Htacces files can get lost or 
corrupted, so....


In my  config file I have the text string.

//region******** htaccess file text ********
// Code writes to /db folder; Admin mode checks file existence and text; 
replaces with this if different.

$htaccessText = <<<hta
# Prevent Direct Access to MiniRegDB DB Files
<Files *>
Order Deny,Allow
Deny from all
</Files>
hta;
//endregion

In my main control file I call this function

/**
* checkHTaccessFile()
*
* Checks and restores htaccess  Prevent Direct Access to MiniRegDB Program Files
*
* @param mixed $htaccessText in config file
* @return
*/
function checkHTaccessFile($htaccessText)
{
     if(file_exists(MINIREG_DATA_DIR . '.htaccess') && 
file_get_contents(MINIREG_DATA_DIR . '.htaccess') == $htaccessText) return true;

     file_put_contents(MINIREG_DATA_DIR . '.htaccess', $htaccessText);
     return true;
}


On 2/20/2010 4:05 AM, 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.
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.