使用 fopen() 包装器创建 ZIP 文件 [英] Create ZIP file with fopen() wrapper
本文介绍了使用 fopen() 包装器创建 ZIP 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用 fopen() 包装器创建 ZIP 文件?这显然不是方式:
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
推荐答案
我最终认为 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.
这篇关于使用 fopen() 包装器创建 ZIP 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文