feha
Posts: 712
|
Posted: 04/14/2006, 5:12 AM |
|
I have developed theese functions in order to create dir's for Users/Clients ...
(Part of Vision.To CMS)
// =======================================================================================================
function VISION_TO_CREATE_DIR($dir_name, $use_chmod = 0)
{
// by www.vision.to
$report = "";
ini_set('display_errors', '0');
if (!file_exists($dir_name))
{
if($use_chmod==1)
{
mkdir ($dir_name, 0777);
}
else
{
mkdir ($dir_name);
}
if (file_exists($dir_name))
{
$report = "Vision.To CMS : DIR ".$dir_name." has been created!";
$filename = $dir_name."index.php";
if (!file_exists($filename)) {
touch($filename); // Create blank file index.php
if($use_chmod==1)
{
chmod($filename,0666);
}
}
$filename = $dir_name."index.html";
if (!file_exists($filename)) {
touch($filename); // Create blank file index.html
if($use_chmod==1)
{
chmod($filename,0666);
}
}
$filename = $dir_name."index.htm";
if (!file_exists($filename)) {
touch($filename); // Create blank file index.htm
if($use_chmod==1)
{
chmod($filename,0666);
}
}
return $report;
}
else
{
$report = "Vision.To CMS Error: DIR ".$dir_name." IS NOT created!";
return $report;
}
}
else
{
$report = "Vision.To CMS Error: DIR ".$dir_name." already exists!";
return $report;
}
}
// =======================================================================================================
function VISION_TO_DELETE_DIR($file,$use_chmod=1)
{
ini_set('display_errors', '0');
if (is_dir($file)) {
$handle = opendir($file);
while($filename = readdir($handle)) {
if ($filename != "." && $filename != "..")
{
VISION_TO_DELETE_DIR($file."/".$filename);
}
}
closedir($handle);
if($use_chmod==1)
{
chmod($file,0777);
}
rmdir($file);
} else {
if($use_chmod==1)
{
chmod($file,0666);
}
unlink($file);
}
}
// =======================================================================================================
example
afterinsert ...
VISION_TO_CREATE_DIR("directory_or_username");
the same way you use the function after delete ...
IF server Supports CHMOD than use:
VISION_TO_CREATE_DIR($user_id,1);
Not only creates directory but two files inside it
index.php and index.html
_________________
Regards
feha
www.vision.to
feedpixel.com |