Change language

PHP Rmdir () function

rmdir (dirname, context)
Parameters used:
The rmdir() function in PHP takes two parameters.
  • dirname:This is a required parameter and specifies the directory to remove.
  • context:this is an optional parameter that determines the behavior of the stream.
  • Return value:
    Returns True on success, or False on failure.Errors and exceptions
  • The rmdir() function generates an E_WARNING level error on failure.
  • opendir() must be closed before using rmdir(), otherwise it will throw an access denied error.
  • PHP checks if the directory in which the script is running has the same UID (owner) as the script, which is 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 
    The programs below illustrate the rmdir() function.Program 1
    // create a directory named gfg mkdir ( ’gfg’ ); $dirname = "gfg" ;  
    // remove directory using rmdir() rmdir ( $dirname ); ?>
    Program 2 // create a directory named gfg $dirname = "gfg" ;  
    // remove directory using rmdir() if ( rmdir ( $dirname )) { echo ( "$dirname successfully removed" ); }
    { echo ( $dirname . "couldn’t be removed" ); }
    gfg successfully removed 
    http : //