PHP Tutorial - PHP rmdir() Function






Definition

The rmdir() function removes an empty directory.

Syntax

rmdir(dir,context)

Parameter

ParameterIs requiredDescription
dirRequired.Directory to be removed
contextOptional.Context of the file handle.

Return

This function returns TRUE on success, or FALSE on failure.

Example

PHP rmdir() takes a directory name and deletes the specified directory. The directory must be empty; otherwise, the call will fail.


<?php
$path = "images";
if(!rmdir($path)){
  echo ("Could not remove $path");
}
?>