首页  >  文章  >  后端开发  >  怎么用php向服务器已存在的zip文件中增加一个文件

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

WBOY
WBOY原创
2016-06-13 13:39:23864浏览

如何用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、不要以为自己总是对的,偶尔也看看别人是不是说的也是对的。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn