Php 编码点火器';s的zip下载文件为空

Php 编码点火器';s的zip下载文件为空,php,codeigniter,Php,Codeigniter,我有一个页面,用户可以选择从不同的作业下载哪些文件。每个作业可能有多个文件。提交表单时,文件将被发送到一个函数,该函数应将文件压缩到不同的作业文件夹中,然后压缩整个文件并下载 一切都很好,只是当我进入下载的zip文件中的每个文件夹时,它会显示其中有一个数组,但它是空的。我不确定我做错了什么 以下是函数: public function downloadDocFiles() { $postdata = $this->input->post(); $this->lo

我有一个页面,用户可以选择从不同的作业下载哪些文件。每个作业可能有多个文件。提交表单时,文件将被发送到一个函数,该函数应将文件压缩到不同的作业文件夹中,然后压缩整个文件并下载

一切都很好,只是当我进入下载的zip文件中的每个文件夹时,它会显示其中有一个数组,但它是空的。我不确定我做错了什么

以下是函数:

public function downloadDocFiles() {
    $postdata = $this->input->post();
    $this->load->library('zip');
    $this->load->library('awss3', null, 'S3');
    foreach ($postdata['files'] as $key => $value) {
        $d = $this->S3->readFile('uploads/' . $key . '/' . $value, true);
        $this->zip->add_data($key . '/' . $value, $d);
    }
    $this->zip->download('Completed Jobs.zip');
}
数据来源如下:

Array
    (
        [files] => Array
            (
                [3454] => Array
                    (
                        [0] => file1.docx
                        [1] => file2.docx
                    )

                [2711] => Array
                   (
                        [0] => nameoffile.docx
                   )

                [1162] => Array
                   (
                        [0] => zyx3.docx
                        [1] => iure8.docx
                   )

             )

)

已下载文件Completed Jobs.zip,其中包含文件夹(3454、2711和1162),但这些文件夹仅包含大小为0的“数组”。

感谢Omas Abbas的帮助

我将我的代码更改为此,它成功了:

public function downloadDocFiles() {
    $postdata = $this->input->post();
    $this->load->library('zip');
    $this->load->library('awss3', null, 'S3');
    foreach ($postdata['files'] as $key => $value) {
        $count = count($postdata['files'][$key]);
        for ($i = 0; $i < $count; $i++) {
            $d = $this->S3->readFile('uploads/' . $key . '/' . $value[$i], true);
            $this->zip->add_data($key . '/' . $value[$i], $d);
        }
    }
    $this->zip->download('Completed Jobs.zip');
}
public函数下载docfiles(){
$postdata=$this->input->post();
$this->load->library('zip');
$this->load->library('awss3',null,'S3');
foreach($postdata['files']作为$key=>$value){
$count=count($postdata['files'][$key]);
对于($i=0;$i<$count;$i++){
$d=$this->S3->readFile('uploads/'.$key./'.$value[$i],true);
$this->zip->add_data($key.'/'.$value[$i],$d);
}
}
$this->zip->download('Completed Jobs.zip');
}

您是否确定文件中是否包含您在写入并创建zip文件之前试图保存的数据?@omarabas,是的,它们确实包含数据。这些作业都是已完成的作业,因此它们肯定不是空的。好的,但您的zip文件似乎正在创建,所有文件和文件夹都正常,但它们不包含任何数据?读取文件时,数组是否为空?是吗?是的,没错。我不确定问题出在哪里。
var\u dump()
在创建文件并查看结果之前写入内容。