2011-02-13 67 views
2

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

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

任何解释赞赏。

 
$zip = new 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('.'); //also tried 
$zip->close(); 

可用
邮编启用
扩展版本$编号:php_zip.c,V 1.1.2.50 2009年3月1日17点35分25秒iliaa精通$
邮编版本1.8.11
Libzip 0.9.0版本

+0

您检查您有权写呢?这些函数返回什么? – Orbling 2011-02-13 18:24:53

回答

1

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

0

退房其他的例子,但是这是我得到它的工作:

<?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(); 

    ?>