【发布时间】:2020-02-12 07:29:10
【问题描述】:
我有一个页面,用户可以在其中选择他们想从不同的作业下载哪些文件。每个作业可能有多个文件。提交表单后,文件被发送到一个函数,该函数应该将它们压缩到不同的工作文件夹中,然后压缩整个文件并下载。
一切都很好,除了当我进入下载的 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。
【问题讨论】:
-
在写入然后创建 zip 文件之前,您是否确定文件是否确实包含您尝试保存的数据?
-
@OmarAbbas,是的,它们确实包含数据。作业都是已经完成的作业,所以肯定不是空的。
-
好的,但您的 zip 文件似乎创建正常,包含所有文件和文件夹,但它们不包含任何数据?当您读取文件时,像数组是空的吗?对吗?
-
是的,正确的。我不确定是什么问题。
-
var_dump()在创建文件之前写入内容并查看结果。
标签: php codeigniter