相关疑难解决方法(0)

删除FTP连接上的文件夹和所有文件

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

我已经建立了一个递归函数来做到这一点,我觉得逻辑是正确的,但仍然行不通。

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

有任何想法吗?

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 …
Run Code Online (Sandbox Code Playgroud)

php ftp rmdir

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

ftp ×1

php ×1

rmdir ×1