rmdir() function in PHP


The rmdir() function removes an empty directory. With that, the file must have the relevant permissions required to delete the directory.

Syntax

rmdir(dir, context)

Parameters

  • rmdir − The directory to be removed.

  • context − Specify the behavior of the stream.

Return

The rmdir() function returns True on success or False on failure.

Example

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

Output

TRUE

Let us see another example.

Example

<?php
   mkdir(‘documents);
   $dir= "documents";
   // using rmdir() to remove directory
   rmdir($dir);
?>

Output

TRUE

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 24-Jun-2020

156 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements