Skip to content

Instantly share code, notes, and snippets.

@erhaem
Created December 11, 2023 08:03
Show Gist options
  • Select an option

  • Save erhaem/f134c2b573832076bd62f82fb562e13f to your computer and use it in GitHub Desktop.

Select an option

Save erhaem/f134c2b573832076bd62f82fb562e13f to your computer and use it in GitHub Desktop.
Used when `upload_max_filesize = 1M`. lmao
<?php
function combineAndExtract($archiveName, $outputDirectory)
{
// Combine split parts into a single ZIP file
$combinedArchivePath = combineSplitZip($archiveName);
// Extract the combined ZIP archive
extractZip($combinedArchivePath, $outputDirectory);
// Optionally, you can delete the combined ZIP file
unlink($combinedArchivePath);
}
function combineSplitZip($archiveName)
{
// Get a list of all split parts
$splitParts = glob($archiveName . '.*');
// Sort the split parts in case the naming is not sequential
sort($splitParts);
// Combine split parts into a single ZIP file
$combinedArchivePath = $archiveName . '.zip';
file_put_contents($combinedArchivePath, '');
foreach ($splitParts as $part) {
$combinedPart = file_get_contents($part);
file_put_contents($combinedArchivePath, $combinedPart, FILE_APPEND);
}
return $combinedArchivePath;
}
function extractZip($archivePath, $outputDirectory)
{
// Create a ZipArchive instance
$zip = new ZipArchive();
// Open the combined ZIP archive
if ($zip->open($archivePath) === true) {
// Extract the contents to the specified directory
$zip->extractTo($outputDirectory);
// Close the archive
$zip->close();
echo 'Extraction successful.';
} else {
echo 'Failed to open ZIP archive.';
}
}
$archiveName = 'api_splitted';
$outputDirectory = 'api_split';
combineAndExtract($archiveName, $outputDirectory);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment