ftp_rmdir

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

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

Описание

bool ftp_rmdir ( resource ftp_stream, string directory )

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

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

ftp_stream

Идентификатор соединения с FTP сервером

directory

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

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

Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.

Примеры

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

<?php

$dir
= 'www/';

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

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

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

ftp_close($conn_id);

?>

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

ftp_mkdir()



ftp_rmdir
mail at martinauer dot net
14-May-2006 10:36
At least in PHP 4.3.11 ftp_nlist lists complete paths, not just filenames. Therefore the function by uma at di4 dot com did not work for me. But it worked with a small change in line 6 like this:

function ftp_rmAll($conn_id,$dst_dir){
   $ar_files = ftp_nlist($conn_id, $dst_dir);
   //var_dump($ar_files);
   if (is_array($ar_files)){ // makes sure there are files
       for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
           $st_file = basename($ar_files[$i]);
           if($st_file == '.' || $st_file == '..') continue;
           if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ // check if it is a directory
               ftp_rmAll($conn_id,  $dst_dir.'/'.$st_file); // if so, use recursion
           } else {
               ftp_delete($conn_id,  $dst_dir.'/'.$st_file); // if not, delete the file
           }
       }
   }
   $flag = ftp_rmdir($conn_id, $dst_dir); // delete empty directories
   //return $flag;
}
uma at di4 dot com
06-Mar-2006 04:06
Removing a directory using FTP(modified Version):
___________________________________________

function ftp_rmAll($conn_id,$dst_dir){
   $ar_files = ftp_nlist($conn_id, $dst_dir);
   //var_dump($ar_files);
   if (is_array($ar_files)){ // makes sure there are files
       for ($i=0;$i<sizeof($ar_files);$i++){ // for each file
           $st_file = $ar_files[$i];
           if($st_file == '.' || $st_file == '..') continue;
           if (ftp_size($conn_id, $dst_dir.'/'.$st_file) == -1){ // check if it is a directory
               ftp_rmAll($conn_id,  $dst_dir.'/'.$st_file); // if so, use recursion
           } else {
               ftp_delete($conn_id,  $dst_dir.'/'.$st_file); // if not, delete the file
           }
       }
   }
   $flag = ftp_rmdir($conn_id, $dst_dir); // delete empty directories
   //return $flag;
}
mvh at list dot ru
02-Mar-2006 05:02
to: turigeza on yahoo com
You have made a mistake in the function. In it parts:
<?php
foreach($list as $value)
  
ftp_rmdirr($value, $handle);
?>

Need:
<?php
foreach($list as $value)
{
   if (
$value != $path . '/.' && $value != $path . '/..')
      
ftp_rmdirr($value, $handle);
}
?>
mgyth_at-online_dot-no
23-Feb-2006 11:19
Worth beeing aware of:
ftp_rmdir scrips that are porly written and require you to supply a $dir to delete, may in some cases, where the $dir is empty, run the script on the your base dir on the server, thus deleting all the files you have ftp acces to.
turigeza on yahoo com
07-Nov-2005 07:15
Recursive directory delete using ftp_nlist() ...
<?php
function ftp_rmdirr($path, $handle)
   {
   if (!(@
ftp_rmdir($handle, $path) || @ftp_delete($handle, $path)))
       {
      
$list = ftp_nlist($handle, $path);
       if (!empty(
$list))
           foreach(
$list as $value)
              
ftp_rmdirr($value, $handle);
       }
   @
ftp_rmdir($handle, $path);
   }
?>
aidan at php dot net
29-Jul-2005 02:28
If you wish to recursively delete a directory and all its contents, see the below function.

http://aidan.dotgeek.org/lib/?file=function.ftp_rmdirr.php

<ftp_renameftp_set_option>
 Last updated: Tue, 15 Nov 2005