duanhuiuw12555 2014-06-17 02:52
浏览 42
已采纳

使用PHP和PCLZip损坏ZIP文件

I'm having some issues, I'm using PCLZip to create an archive. I don't get any errors, the zip file is created, but when I go to view it, the archive is empty and on my windows machine I get an error "The Compressed (zipped) folder "local directory zip file") is invalid. I have the following code:

$dir = '../downloads/liability/';
$archive = new PclZip($dir.'archive.zip');
$v_list = $archive->create($dir);
    if ($v_list == 0) {
        die("Error : ".$archive->errorInfo(true));
    }

My directory structure is:

-admin
  --liabilityDev.php (where the above code resides)
  --index.php
  --commission.php
-downloads
  --liability
    ---one.pdf
    ---two.pdf

The end result is that in the liability folder, there is a file called archive.zip which contains the 2 pdf's but I get the invalid error. If I don't have the directory variable, I archive index.php and commission.php and that works fine. It leads me to believe it may be a permission issue, but I'm running on fumes now. Please help!

  • 写回答

1条回答 默认 最新

  • doutong4088 2014-06-17 08:07
    关注

    You can try this:

    if(extension_loaded('zip')){
     $zip = new ZipArchive();
     if($zip->open('../downloads/liability/archive.zip', ZIPARCHIVE::CREATE)===TRUE){
       $zip->addFile('path of any normal file to be add into zip');  
     }
     $zip->close();
    }  
    

    I think, this will fullfill your need. Before implementing this code, please check first that, zip extension is already loaded or not.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘