>  기사  >  백엔드 개발  >  怎么用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으로 문의하세요.