无法打开zip文件,代码符号 [英] Unable to open zip file, codeigniter

查看:159
本文介绍了无法打开zip文件,代码符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将用户上传的图片添加到zip文件中。因此,该用户可以下载此文件。
问题是当我下载这个zip文件,它包含大量的文件名(如我所料)。但是当我打开这个zip,它显示我的错误
C:.... ata\Local\Temp\my_photo.zip:归档的意外结束

I tried to add my pictures, which uploaded by users, into a zip file. so, that user can download this file. The problem is when I download this zip file, it contains lots of filename (as I expect). But when I open this zip, it show me error "C:....ata\Local\Temp\my_photo.zip: Unexpected end of archive"

每张图片都有大小,但CRC32是00000000
这是代码:

Each picture has size but CRC32 is 00000000 Here is the code:

 $this->load->library('zip');
 $this->zip->clear_data();
 foreach ($row as $ar){
    $file_relative_path = $ar->filepath;               
     if(file_exists($file_relative_path)){
           $this->zip->add_data($this->_getFileName($file_relative_path),file_get_contents($file_relative_path));
     }
}
$this->zip->download('my_photo.zip');  


推荐答案

尝试在最后一行之前添加: p>

Try adding this right before the last line:

$this->zip->archive('my_photo.zip');

我在文档

我猜这可能有时会工作,但是可能会在您的案例中发送标题,因此您需要使用归档方法。

I'm guessing that this might work sometimes, but maybe headers are being sent in your case, so you need to use the archive method.

这篇关于无法打开zip文件,代码符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆