ftp_rmdir

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_rmdirУдаляет директорию

Описание

ftp_rmdir(FTP\Connection $ftp, string $directory): bool

Удаляет директорию directory.

Список параметров

ftp

Экземпляр класса FTP\Connection.

directory

Имя директории. Параметр должен содержать относительный или абсолютный путь к пустой директории.

Возвращаемые значения

Функция возвращает true, если выполнилась успешно, или false, если возникла ошибка.

Список изменений

Версия Описание
8.1.0 Параметр ftp теперь ожидает экземпляр класса FTP\Connection; раньше параметр ждал ресурс (resource).

Примеры

Пример #1 Пример использования ftp_rmdir()

<?php

$dir
= 'www/';

// установка соединения
$ftp = ftp_connect($ftp_server);

// проверка имени пользователя и пароля
$login_result = ftp_login($ftp, $ftp_user_name, $ftp_user_pass);

// попытка удаления директории $dir
if (ftp_rmdir($ftp, $dir)) {
echo
"Директория $dir удалена\n";
} else {
echo
"Не удалось удалить директорию $dir\n";
}

ftp_close($ftp);

?>

Смотрите также

Добавить

Примечания пользователей 2 notes

up
5
karl AT karlgroves.com
14 years ago
Please note that this function, like rmdir, requires that the directory be empty.
up
4
johan dot kerreneur at gmail dot com
5 years ago
ftp_rmdir() delete only empty folders...if you want to delete the entire contents of a folder try its.Exemple...<?php$ftp_server = "YourIP";$ftp_user_name = "YourUsername";$ftp_user_pass = "YourPassword";// Connectionecho "Connecting to $ftp_server";$conn_id = ftp_connect($ftp_server);$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);//Enable PASV ( Note: must be done after ftp_login() )ftp_pasv($conn_id, true);// check connectionif((!$conn_id) || (!$login_result)){    die("FTP connection has failed !");}echo "<br/>Login Ok.";// Function to delete an entire folderfunction ftp_rrmdir($conn_id, $directory){    $lists = ftp_mlsd($conn_id, $directory);    unset($lists[0]);    unset($lists[1]);    foreach($lists as $list){        $full = $directory . '/' . $list['name'];        if($list['type'] == 'dir'){            ftp_rrmdir($conn_id, $full);        }else{            ftp_delete($conn_id, $full);        }    }    ftp_rmdir($conn_id, $directory);    return true;}//Now run ftp_rrmdir()if(ftp_rrmdir($conn_id, 'YOUR/PATH/')){    echo = "Folder deleted !";}//closeftp_close($conn_id);?>
To Top