<legend id='sjOHu'><style id='sjOHu'><dir id='sjOHu'><q id='sjOHu'></q></dir></style></legend>

      <bdo id='sjOHu'></bdo><ul id='sjOHu'></ul>

    <small id='sjOHu'></small><noframes id='sjOHu'>

      <i id='sjOHu'><tr id='sjOHu'><dt id='sjOHu'><q id='sjOHu'><span id='sjOHu'><b id='sjOHu'><form id='sjOHu'><ins id='sjOHu'></ins><ul id='sjOHu'></ul><sub id='sjOHu'></sub></form><legend id='sjOHu'></legend><bdo id='sjOHu'><pre id='sjOHu'><center id='sjOHu'></center></pre></bdo></b><th id='sjOHu'></th></span></q></dt></tr></i><div id='sjOHu'><tfoot id='sjOHu'></tfoot><dl id='sjOHu'><fieldset id='sjOHu'></fieldset></dl></div>

      <tfoot id='sjOHu'></tfoot>
    1. 删除 FTP 连接上的文件夹和所有文件

      Delete folder and all files on FTP connection(删除 FTP 连接上的文件夹和所有文件)

      <legend id='Ge2D1'><style id='Ge2D1'><dir id='Ge2D1'><q id='Ge2D1'></q></dir></style></legend>
        1. <i id='Ge2D1'><tr id='Ge2D1'><dt id='Ge2D1'><q id='Ge2D1'><span id='Ge2D1'><b id='Ge2D1'><form id='Ge2D1'><ins id='Ge2D1'></ins><ul id='Ge2D1'></ul><sub id='Ge2D1'></sub></form><legend id='Ge2D1'></legend><bdo id='Ge2D1'><pre id='Ge2D1'><center id='Ge2D1'></center></pre></bdo></b><th id='Ge2D1'></th></span></q></dt></tr></i><div id='Ge2D1'><tfoot id='Ge2D1'></tfoot><dl id='Ge2D1'><fieldset id='Ge2D1'></fieldset></dl></div>

              <tfoot id='Ge2D1'></tfoot>
                <tbody id='Ge2D1'></tbody>
              • <bdo id='Ge2D1'></bdo><ul id='Ge2D1'></ul>
              • <small id='Ge2D1'></small><noframes id='Ge2D1'>

              • 本文介绍了删除 FTP 连接上的文件夹和所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                尝试添加使用 FTP 删除文件夹以及该文件夹中包含的所有子文件夹和文件的功能.

                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 feel like the logic is right, but still doesnt work.

                我做了一些测试,如果路径只是一个空文件夹或只是一个文件,我可以在第一次运行时删除,但如果它是包含一个文件的文件夹或包含一个空子文件夹的文件夹,则无法删除.因此,遍历文件夹并使用删除功能似乎是一个问题.

                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.

                有什么想法吗?

                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);
                    }
                };
                

                推荐答案

                好的,找到了我的问题.由于我没有移动到我试图删除的确切目录,因此每个被调用的递归文件的路径都不是绝对的:

                Ok found my problem. Since I wasn't moving into the exact directory I was trying to delete, the path for each recursive file being called wasn't absolute:

                function ftpDeleteDirectory($directory)
                {
                    global $conn_id;
                    if(empty($directory))//Validate that a directory was sent, otherwise will delete ALL files/folders
                        return json_encode(false);
                    else{
                        # 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)
                            {
                            //  return json_encode($filelist);
                                ftpDeleteDirectory($directory.'/'.$file);/***THIS IS WHERE I MUST RESEND ABSOLUTE PATH TO FILE***/
                            }
                
                            #if the file list is empty, delete the DIRECTORY we passed
                            ftpDeleteDirectory($directory);
                        }
                    }
                    return json_encode(true);
                };
                

                这篇关于删除 FTP 连接上的文件夹和所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <i id='3Rhb6'><tr id='3Rhb6'><dt id='3Rhb6'><q id='3Rhb6'><span id='3Rhb6'><b id='3Rhb6'><form id='3Rhb6'><ins id='3Rhb6'></ins><ul id='3Rhb6'></ul><sub id='3Rhb6'></sub></form><legend id='3Rhb6'></legend><bdo id='3Rhb6'><pre id='3Rhb6'><center id='3Rhb6'></center></pre></bdo></b><th id='3Rhb6'></th></span></q></dt></tr></i><div id='3Rhb6'><tfoot id='3Rhb6'></tfoot><dl id='3Rhb6'><fieldset id='3Rhb6'></fieldset></dl></div>
                    <tbody id='3Rhb6'></tbody>
                  <tfoot id='3Rhb6'></tfoot>
                    • <legend id='3Rhb6'><style id='3Rhb6'><dir id='3Rhb6'><q id='3Rhb6'></q></dir></style></legend>
                    • <small id='3Rhb6'></small><noframes id='3Rhb6'>

                          <bdo id='3Rhb6'></bdo><ul id='3Rhb6'></ul>