如何使用php从amazon s3存储桶中的子文件夹下载文件?

I have vendor folder in my local.

I want to download a file from a sub folder which is inside my bucket's folder, to my computer's directory with the same name.

Let's say there is a bucket name "ABC" a folder is there inside it, is "DEF" And there is a sub folder named "XYZ" in "DEF". In which the files are present in folder "XYZ".

So, anyone can help me in resolving this?

function downloadFromS3($s3version,$s3region,$s3accesskey,$s3secret,$bucket,$directory){
        $s3 = new S3Client([
            'version' => $s3version,
            'region'  => $s3region,
            'credentials' =>
            array(
                'key'=>$s3accesskey,
                'secret'  =>$s3secret
            )
        ]);

        try {
            $basePath = 'downloads/';

            $s3->downloadBucket($basePath . $directory, $bucket, $directory);
        }
       catch (Aws\S3\Exception\S3Exception $e) {
            echo $e->getMessage();
            echo "There was an error uploading the file.
";
        }
    }

I am getting error like

 Warning: count(): Parameter must be an array or an object that implements Countable in C:\xampp\htdocs\Performance\TestManagement\vendor\guzzlehttp\guzzle\src\Handler\CurlFactory.php on line 67

Thanks in advance..