我有一个包含许多PDF文件的文件夹。我已经构建了一个脚本,将这些pdf文件分别压缩为100mb。
#!/usr/bin/php
<?php
$pathToFiles = "../pdffakturor_test/";
$maxFileSize = 100 * 1024 * 1024;
$counter = 1;
$currentsize = 0;
$created_at_datum = date("Ymd");
$created_at_clock = date("Hi");
$zip = new ZipArchive;
if($counter <= 10)
{
$counter = sprintf("%02s", $counter);
}
$zip->open('PROD_SE_C_S_E_'.$created_at_datum.'_'.$created_at_clock.$counter.'.zip', ZipArchive::CREATE);
if ($handle = opendir($pathToFiles))
{
while (false !== ($entry = readdir($handle)))
{
if (substr($entry, -4) == ".pdf")
{
$filesize = filesize($pathToFiles.$entry);
if($currentsize >= $maxFileSize)
{
$zip->close();
$zip = null;
$zip = new ZipArchive;
$currentsize = 0;
if($counter <= 10)
{
$counter = sprintf("%02s", $counter);
}
$zip->open('PROD_SE_C_S_E_'.$created_at_datum.'_'.$created_at_clock.$counter.'.zip', ZipArchive::CREATE);
$counter++;
}
$zip->addFile($pathToFiles.$entry, $entry);
$currentsize += $filesize;
}
}
closedir($handle);
}
?>
我遇到的问题是第一个拉链批次为183mb,其他为91,6mb。我无法弄清楚为什么第一个变成了183mb?