PHP ZipArchive没有添加任何文件(Windows)
发布时间:2020-12-13 17:50:58 所属栏目:PHP教程 来源:网络整理
导读:我没有把一个文件放到一个新的zip存档中. makeZipTest.php: ?php$destination = __DIR__.'/makeZipTest.zip';$fileToZip = __DIR__.'/hello.txt';$zip = new ZipArchive();if (true !== $zip-open($destination,ZIPARCHIVE::OVERWRITE)) { die("Problem ope
我没有把一个文件放到一个新的zip存档中.
makeZipTest.php: <?php $destination = __DIR__.'/makeZipTest.zip'; $fileToZip = __DIR__.'/hello.txt'; $zip = new ZipArchive(); if (true !== $zip->open($destination,ZIPARCHIVE::OVERWRITE)) { die("Problem opening zip $destination"); } if (!$zip->addFile($fileToZip)) { die("Could not add file $fileToZip"); } echo "numfiles: " . $zip->numFiles . "n"; echo "status: " . $zip->status . "n"; $zip->close(); zip已创建,但为空.然而,没有触发任何错误. 出了什么问题?
在某些配置中,当将文件添加到zip存档时,PHP无法正确获取本地名称,并且必须手动提供此信息.因此,使用addFile()的第二个参数可能会解决此问题.
PHP documentation: ZipArchive::addFile $zip->addFile( $fileToZip,basename($fileToZip) ); 您可能必须调整代码以获得正确的树结构,因为basename()将从文件名之外的路径中删除所有内容. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |