Oct
14

One of the functions that might be very useful for web development is to create a protected folder on the fly so you can upload files for example without worrying that anyone can access these files.

/**
* Create .htaccess protected folder
*
* @param $folder folder path
* @return
**/
function smkdir($folder){

if (!is_dir($folder)) {
mkdir($folder,0777);
}

if (!$handle = fopen($folder.”.htaccess”, ‘a’)) {
echo “Impossible d’ouvrir le fichier ($filename)”;
exit;
}
$protect = “AuthType Basic
AuthName “No access”
AuthUserFile .htnopasswd
AuthGroupFile /dev/null
Require valid-user
“;
fwrite($handle, $protect);
fclose($handle);
}


This function could be also useful to create folder with a specified home page inside or redirection. To use it, imagine we want to install an application that create alphabetic folders to organize projects or other.

/**
* Check if fonts folder isn’t created and create it.
*
* @param $base base path to create folder inside
* @return
**/
function install_check($base)
{

if (!is_dir($base)) {
smkdir($base);

for($i = 65; $i

Hope it could be helpful

Tags: No Tags

2 Responses

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>