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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀