<?php
$directory = 'files';
$path = __DIR__ . '/' . $directory;
$filename = sprintf('%s.zip', $path);
$zip = new ZipArchive;
$zip->open($filename, ZipArchive::CREATE);
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $name => $file) {
if (! $file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($path) + 1);
$zip->addFile($filePath, $relativePath);
}
}
$zip->close();
|
Web Majster - triki i rozwiązania. Pokazuję ciekawe rozwiązania w PHP, frameworku Kohana PHP, JavaScript i jQuery, htaccess i mod_rewrite oraz inne.
środa, 6 stycznia 2016
Jak stworzyć archiwum Zip w PHP
Przykład rekursywnego tworzenia archiwum Zip:
Subskrybuj:
Komentarze do posta (Atom)
Brak komentarzy:
Prześlij komentarz