簡體   English   中英

php zip檔案

[英]php zip archive

我試圖創建空/非空的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();

可得到
啟用拉鏈
擴展版本$ Id:php_zip.c,v 1.1.2.50 2009/03/01 17:35:25 iliaa Exp $
郵編1.8.11
Libzip 0.9.0版

ZipArchive方法通過返回false來指示失敗。 你檢查了嗎? 您檢查過getStatusString嗎?

查看其他示例,但這是我如何使其工作的方式:

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

    ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM