/*---------------------------------------------------------------*/
|
/*
|
Titre : Destruction d'un répertoire FTP
|
|
URL : https://phpsources.net/code_s.php?id=844
|
Date édition : 14 Fév 2019
|
*/
|
/*---------------------------------------------------------------*/
|
|
function ftp_rm($host , $user , $passwd , $dir , $port=21){
|
/* Paramètres :
|
* $host : adresse du serveur FTP
|
* $user : login
|
* $passwd : mot de passe
|
* $dir : repertoire a supprimer
|
* $port : port de connexion (par defaut 21)
|
*/
|
$nb=0;
|
if (func_num_args() == 6)
|
{
|
$stream = func_get_args(5);
|
}
|
else
|
{
|
$stream = ftp_connect($host, $port);
|
if (!ftp_login($stream, $user, $passwd))
|
return FALSE;
|
if (!preg_match("/^\//", $dir))
|
$dir = "/$dir";
|
if (!ftp_chdir($stream, $dir))
|
return FALSE;
|
}
|
$list = ftp_nlist($stream, '.');
|
if (is_array($list))
|
{
|
$pwd = ftp_pwd($stream);
|
while(list($k, $v) = each($list))
|
{
|
if (@ftp_chdir($stream, "$pwd/$v"))
|
{
|
$nb += ftp_rm($host, $user, $passwd, "$pwd/$v", $port, $stream);
|
}
|
else
|
{
|
if (ftp_delete($stream, $v))
|
$nb++;
|
}
|
}
|
}
|
if (ftp_rmdir($stream, $dir))
|
$nb++;
|
return $nb;
|
}
|
|
| ?> |