csvxml/public/zipit.php
Joshua Ramon Enslin d56601b0cc
Move public files to /public subdirectory
phpcs-errors:221 phpunit-status:successful phpstan-errors:0
2020-10-31 00:00:26 +01:00

44 lines
1.3 KiB
PHP

<?PHP
require_once __DIR__ . "/../inc/zip.php";
require_once __DIR__ . "/../functions/functions.php";
$fileTime = date("D, d M Y H:i:s T");
$fileDir = __DIR__ . '/../xml/';
$zip = new Zip();
//$zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
if ($handle = opendir($fileDir)) {
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
if (strpos($file, ".xml") !== false) {
$pathData = pathinfo($fileDir . $file);
$fileName = $pathData['filename'];
if ($file != '1.xml')
$zip->addFile(MD_STD::file_get_contents($fileDir . $file), $file, filectime($fileDir . $file));
}
}
}
if (ini_get('zlib.output_compression')) {
ini_set('zlib.output_compression', 'Off');
}
$zip->finalize(); // Not scrictly necessary, the next line will call it anyway.
$zipData = $zip->getZipData();
$length = strlen($zipData);
header('Pragma: public');
header("Last-Modified: " . $fileTime);
header("Expires: 0");
header("Accept-Ranges: bytes");
header("Connection: close");
header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="csv_xml.zip";' );
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $length);
echo $zipData;
rrmdir(__DIR__ . '/../xml');