title: Delete folder and all files on FTP connection
body: <p>Trying to add the ability to delete a Folder using FTP and all subfolders and files contained within that folder.</p>
  
  <p>I have built a recursive function to do so, and I feel like the logic is right, but still doesnt work.</p>
  
  <p>I did some testing, I am able to delete on first run if the path is just an empty folder or just a file, but can't delete if it is a folder containing one file or a folder containing one empty subfolder. So it seems to be a problem with traversing through the folder(s) and using the function to delete.</p>
  
  <p>Any ideas?</p>
  
  <pre><code>function ftpDelete($directory)
  {
      if(empty($directory))//Validate that a directory was sent, otherwise will delete ALL files/folders
          return json_encode(false);
      else{
          global $conn_id;
          # here we attempt to delete the file/directory
          if( !(@ftp_rmdir($conn_id,$directory) || @ftp_delete($conn_id,$directory)) )
          {
              # if the attempt to delete fails, get the file listing
              $filelist = @ftp_nlist($conn_id, $directory);
  
              # loop through the file list and recursively delete the FILE in the list
              foreach($filelist as $file)
                  ftpDelete($file);
  
              #if the file list is empty, delete the DIRECTORY we passed
              ftpDelete($directory);
          }
          else
              return json_encode(true);
      }
  };
  </code></pre>