次のコードを使用して、画像フォルダーを一度に圧縮しています。
<?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 です。だから私はこの最後の画像の後にすべての画像を圧縮したい. しかし、私はこれを行う方法を理解することができませんか?