Example 1 — Remove an Empty Folder
Create a temporary folder and then remove it again.
<?php
$ftp = ftp_connect('ftp.example.com');
ftp_login($ftp, 'demo', 'secret');
ftp_mkdir($ftp, 'temp');
echo "Created temp", PHP_EOL;
if (ftp_rmdir($ftp, 'temp')) {
echo "Removed temp", PHP_EOL;
}
ftp_close($ftp); How It Works
- ftp_mkdir() makes a new empty folder called temp.
- ftp_rmdir() is then called on the same folder.
- Because it is empty, the server allows the removal.
- The function returns true, so the second message is printed.

