PHP | rmdir( ) Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The rmdir() function in PHP is an inbuilt function which is used to remove an empty directory. It is mandatory for the directory to be empty, and it must have the relevant permissions which are required to delete the directory. The directory to be deleted is sent as a parameter to the rmdir() function and it returns True on success or False on failure. Syntax: rmdir(dirname, context) Parameters Used: The rmdir() function in PHP accepts two parameters. dirname : It is a mandatory parameter which specifies the directory to be deleted. context : It is an optional parameter which specifies the behavior of the stream . Return Value: It returns True on success or False on failure. Errors And Exception The rmdir() function generates an E_WARNING level error on failure. opendir() must be closed before using rmdir() function else it gives permission denied error. PHP checks whether the directory in which the script is operating has the same UID (owner) as the script that is being executed when it is in safe mode. Examples: Input : mkdir('gfg'); $dirname= "gfg"; rmdir($dirname); Output : 1 Input : $dirname = "gfg"; if(rmdir($dirname)) { echo ("$dirname successfully removed"); } else { echo ("$dirname couldn't be removed"); } Output : gfg successfully removed Below programs illustrate the rmdir() function. Program 1 php <?php // creating a directory named gfg mkdir('gfg'); $dirname= "gfg"; // removing directory using rmdir() rmdir($dirname); ?> Output: 1 Program 2 php <?php // creating a directory named gfg $dirname = "gfg"; // removing directory using rmdir() if(rmdir($dirname)) { echo ("$dirname successfully removed"); } else { echo ($dirname . "couldn't be removed"); } ?> Output: gfg successfully removed Reference: https://www.php.net/manual/en/function.rmdir.php Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-function Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like