如何使用 fopen() wrapper 创建 ZIP 文件?这显然不是方式:
<?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;
}
...因为我得到的是:
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
最佳答案
我最终假设zip:
wrapper 支持写入的说法是一个文档错误,reported it as such .错误报告已被接受并修复。
关于php - 使用 fopen() 包装器创建 ZIP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5620769/