note 124946 added to function.ftp-rmdir
| From: | johan dot kerreneur at gmail dot com | Date: | Sun, 26 Apr 2020 03:34:42 +0000 |
| Subject: | note 124946 added to function.ftp-rmdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214536@lists.php.net to get a copy of this message | ||
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";
// Connection
echo "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 connection
if((!$conn_id) || (!$login_result)){
die("FTP connection has failed !");
}
echo "<br/>Login Ok.";
// Function to delete an entire folder
function 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 !";
}
//close
ftp_close($conn_id);
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.195 (proxied: 2a01:cb08:8892:bc00:8c2f:6a00:78e5:faa2)
----
Manual Page -- http://php.net/manual/en/function.ftp-rmdir.php
Edit -- https://master.php.net/note/edit/124946
Del: integrated -- https://master.php.net/note/delete/124946/integrated
Del: useless -- https://master.php.net/note/delete/124946/useless
Del: bad code -- https://master.php.net/note/delete/124946/bad+code
Del: spam -- https://master.php.net/note/delete/124946/spam
Del: non-english -- https://master.php.net/note/delete/124946/non-english
Del: in docs -- https://master.php.net/note/delete/124946/in+docs
Del: other reasons-- https://master.php.net/note/delete/124946
Reject -- https://master.php.net/note/reject/124946
Search -- https://master.php.net/manage/user-notes.php