Home  >  Article  >  Backend Development  >  怎么用php向服务器已存在的zip文件中增加一个文件

怎么用php向服务器已存在的zip文件中增加一个文件

WBOY
WBOYOriginal
2016-06-13 10:13:141505browse

如何用php向服务器已存在的zip文件中增加一个文件
请注意,不是生成zip,在不解开服务器zip文件的前提下,添加一个文件进去。请问我该如何做。

------解决方案--------------------
加一个zip模块进去
使用方式如下:

$zip = new ZipArchive();
$filename = "./test112.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open \n");
}

$zip->addFromString("testfilephp.txt" . time(), "#1 This is a test string added as testfilephp.txt.\n");
$zip->addFromString("testfilephp2.txt" . time(), "#2 This is a test string added as testfilephp2.txt.\n");
$zip->addFile($thisdir . "/too.php","/testfromfile.php");
echo "numfiles: " . $zip->numFiles . "\n";
echo "status:" . $zip->status . "\n";
$zip->close();
?>
------解决方案--------------------
另外想说:
1、永远不要责怪别人不明白,只能责怪自己没说清楚。
2、不要以为自己总是对的,偶尔也看看别人是不是说的也是对的。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn