使用 fopen() 包装器创建 ZIP 文件
如何使用 fopen() 包装器 创建 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终认为
zip:
包装器支持写入的声明是一个文档错误,并且 如此报道。错误报告已被接受并修复。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.