Files
zurawik.pl/pack.php
2026-05-15 20:23:25 +02:00

41 lines
1.0 KiB
PHP

<?php
//$tarfile = dirname(__FILE__)."/makl_backup.tar";
//$pd = new \PharData($tarfile);
//$pd->buildFromDirectory(dirname(__FILE__));
//$pd->compress(\Phar::GZ);
//print_r($pd);
// Get real path for our folder
$rootPath = realpath(dirname(__FILE__));
// Initialize archive object
$zip = new ZipArchive();
$zip->open('makl_backup.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($rootPath),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file)
{
// Skip directories (they would be added automatically)
if (!$file->isDir())
{
// Get real and relative path for current file
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($rootPath) + 1);
// Add current file to archive
$zip->addFile($filePath, $relativePath);
}
}
print_r($zip);
// Zip archive will be created only after closing object
$zip->close();