Create ZIP file with fopen() wrapper

你说的曾经没有我的故事 提交于 2019-12-10 16:45:59

问题


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 open file

回答1:


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.



来源:https://stackoverflow.com/questions/5620769/create-zip-file-with-fopen-wrapper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!