$rePath = '/uploads/report/'.$fileName;
$zipName = realpath(dirname(__FILE__).'/../../admin').$rePath;
//这是要打包的文件地址数组
$zip = new ZipArchive();
$res = $zip->open($zipName,ZipArchive::CREATE|ZipArchive::OVERWRITE);
if ($res === TRUE) {
foreach ($files as $file) {
$file1 = realpath(dirname(__FILE__).'/../../admin').$file;
//这里直接用原文件的名字进行打包,也可以直接命名,需要注意如果文件名字一样会导致后面文件
//覆盖前面的文件,所以建议重新命名
$new_filename = substr($file1, strrpos($file1, '/') + 1);
$zip->addFile($file1, $new_filename);
}
//关闭文件
$zip->close();
}
PHP zip压缩文件
最新推荐文章于 2025-01-16 10:39:48 发布