Delete folder and all files on FTP connection

后端 未结 4 1148
春和景丽
春和景丽 2020-12-11 08:29

Trying to add the ability to delete a Folder using FTP and all subfolders and files contained within that folder.

I have built a recursive function to do so, and I f

4条回答
  •  难免孤独
    2020-12-11 09:04

    I took some time to write my own version of a recursive delete function over ftp, this one should be fully functional (I tested it myself).

    Try it out and modify it to fit your needs, if it's still not working there are other problems. Have you checked the permissions on the files you are trying to delete?

    function ftp_rdel ($handle, $path) {
    
      if (@ftp_delete ($handle, $path) === false) {
    
        if ($children = @ftp_nlist ($handle, $path)) {
          foreach ($children as $p)
            ftp_rdel ($handle,  $p);
        }
    
        @ftp_rmdir ($handle, $path);
      }
    }
    

提交回复
热议问题