【问题标题】:php zip archivephp 压缩包
【发布时间】:2011-06-26 12:53:14
【问题描述】:

我尝试创建空/非空 zip 存档。
使用的代码如下。

结果:什么也没发生。
没有错误,但也没有结果。

任何解释表示赞赏。

$zip = 新的 ZipArchive(); $zip->open('/home/admin/domains/domain.com/public_html/xxx_zip.zip', ZIPARCHIVE::CREATE); $zip->addFile('/home/admin/domains/domain.com/public_html/xxxxxx.css'); #$zip->addEmptyDir('.'); //也试过了 $zip->close();

可用
已启用 Zip
扩展版本 $Id: php_zip.c,v 1.1.2.50 2009/03/01 17:35:25 iliaa Exp $
Zip 版本 1.8.11
Libzip 版本 0.9.0

【问题讨论】:

  • 你检查过你有写那里的权限吗?这些函数返回了什么?
  • if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) { exit("无法打开 \n"); } 看看打开是否失败
  • 我觉得自己很傻。这些是权限。应该是第一手怀疑的。谢谢Orbling的提示。和你们所有人花时间阅读它。干杯。杰夫

标签: php zip archive


【解决方案1】:

查看其他示例,但这就是我的工作方式:

    <?php

        $dirArray = array();

        /* creates a compressed zip file */
        $zip = new ZipArchive;
        if ($zip->open('dataminefiles.zip', ZIPARCHIVE::CREATE) !== TRUE) {
            die ("Could not open archive"); 
        }
        // open the current dir
        if ($handle = opendir('.')) {
        while (false !== ($entry = readdir($handle))) {
            // ignore hidden files          
            if ($entry != "." && $entry != "..") {
            // only zip specific files
                if ( substr($entry,-3,3) == "jpg" || substr($entry,-3,3) == "pdf" || substr($entry,-3,3) == "lsx" || substr($entry,-3,3) == "xls" || substr($entry,-3,3) == "doc" || substr($entry,-3,3) == "txt" || substr($entry,-3,3) == "png" || substr($entry,-3,3) == "gif" || substr($entry,-3,3) == "peg" ) {
                    // if allowed, add them to the array
                    $dirArray[] = $entry;
                }
            }
        }
        closedir($handle);
    }

        $indexCount = count($dirArray);
        sort($dirArray);
            // loop through the files and add them to the zip file
        for($index=0; $index < $indexCount; $index++) {
                $file = "{$dirArray[$index]}";
                $zip->addFile($file, $file);
        }
    // close the zip file
        $zip->close();

    ?>

【讨论】:

    【解决方案2】:

    ZipArchive 方法通过返回 false 来指示失败。你检查了吗?你检查getStatusString了吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 2014-01-06
      • 1970-01-01
      • 1970-01-01
      • 2023-04-06
      • 2016-04-22
      相关资源
      最近更新 更多