0

我正在使用以下代码一次压缩图像文件夹:

<?php
// increase script timeout value
ini_set("max_execution_time", 300);
// create object
$zip = new ZipArchive();
// open archive
if ($zip->open("my-archive.zip", ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("images"));
// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}
// close and save archive
$zip->close();
echo "Archive created successfully.";
?>

但是图像太多,无法一次压缩。我有 70% 的图像,只想压缩 30% 的图像。最后的图像名称是 XYZ.jpg。所以我想在最后一张图片之后压缩所有图片。但我无法弄清楚如何做到这一点?

4

0 回答 0