PHP/File Directory/Directory Create Delete
Creating and Destroying a Directory Handle
<?php
if (file_exists("./")) {
if (is_dir ("./")) {
$dh = opendir("./") or die (" Directory Open failed !");
echo "Directory was opened successfully";
closedir ($dh);
}
}
?>
Delete an empty directory called dir1
<?php
$dir_delete = "/home/fake/dir1";
if (rmdir ($dir_delete)) {
echo "Directory deleted successfully.", "\n";
}else {
echo "Could not delete the directory.", "\n";
}
?>
Deleting a Directory by Using rmdir()
<?php
if (file_exists("./dummydir")) {
if(is_dir("./dummydir")) {
$result = rmdir("./dummydir");
echo "Result = " . $result;
}
}
?>