从服务器上的文件夹压缩,说2个文件最简单的方法是什么?强行下载?不保存"zip"到服务器.
$zip = new ZipArchive();
//the string "file1" is the name we're assigning the file in the archive
$zip->addFile(file_get_contents($filepath1), 'file1'); //file 1 that you want compressed
$zip->addFile(file_get_contents($filepath2), 'file2'); //file 2 that you want compressed
$zip->addFile(file_get_contents($filepath3), 'file3'); //file 3 that you want compressed
echo $zip->file(); //this sends the compressed archive to the output buffer instead of writing it to a file.
Run Code Online (Sandbox Code Playgroud)
有人可以验证:我有一个包含test1.doc,test2.doc和test3.doc的文件夹
使用上面的示例 - file1(file2和file3)可能只是test1.doc等.
我必须对"$ filepath1"做任何事情吗?这是包含3个文档的文件夹目录吗?
对不起我的基本问题..