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 Create Quiz Comment S Shubrodeep Banerjee Follow 0 Improve S Shubrodeep Banerjee Follow 0 Improve Article Tags : Misc Web Technologies PHP PHP-function Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like