开发者

Create ZIP file with fopen() wrapper

开发者 https://www.devze.com 2023-02-24 07:15 出处:网络
How can you create a ZIP file using the fopen() wrapper? This is obviously not the way: <?php if( class_exists(\'ZipArchive\') ){

How can you create a ZIP file using the fopen() wrapper? This is obviously not the way:

<?php

if( class_exists('ZipArchive') ){
    echo 'Class ZipArchive exists, generating file...' . PHP_EOL;

    $fp = fopen('zip://' . dirname(__FILE__) . '/test.zip', 'w');
    if($fp){
        fwrite($fp, 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.');
        fclose($fp);
        echo 'Done' . PHP_EOL;
    }else{
        echo 'Could not open file' . PHP_EOL;
    }
}else{
    echo 'Class Zip is not available' . PHP_EOL;
}

... because all I get is:

Class ZipArchive exists, generating file...

Warning: fopen(zip://C:\tmp/test.zip) [http://es.php.net/function.fopen]: failed to open stream: operation failed in C:\tmp\test.php on line 6
Could not o开发者_如何学Cpen file


I finally assumed that the claim that zip: wrapper supports writing was a documentation error and reported it as such. The bug report was accepted and fixed.

0

精彩评论

暂无评论...
验证码 换一张
取 消