PHP Files n Directory manipulation

0 comments

Create Directory

mkdir("/path/to/my/dir", 0700);
?>

delete dir
rmdir($dir);

Permissions :

chmod("/adirectory/", 0777); //Will CHMOD a directory
chmod("/adirectory/afile.txt",0777); //Will CHMOD a file


delete file:
// Then unlink :)
unlink($somefile);


example:

function SureRemoveDir($dir, $DeleteMe) {
if(!$dh = @opendir($dir)) return;
while (false !== ($obj = readdir($dh))) {
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.'/'.$obj)) SureRemoveDir($dir.'/'.$obj, true);
}

closedir($dh);
if ($DeleteMe){
@rmdir($dir);
}
}