csvxml/zipit.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2019-08-25 21:45:52 +02:00
<?PHP
2019-08-27 00:31:46 +02:00
require_once "inc/zip.php";
require_once __DIR__ . "/functions/functions.php";
2019-08-25 21:45:52 +02:00
$fileTime = date("D, d M Y H:i:s T");
2019-08-27 00:31:46 +02:00
$fileDir = 'xml/';
2019-08-25 21:45:52 +02:00
$zip = new Zip();
//$zip->setComment("Example Zip file.\nCreated on " . date('l jS \of F Y h:i:s A'));
if ($handle = opendir($fileDir)) {
2019-08-27 00:31:46 +02:00
/* 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(file_get_contents($fileDir . $file), $file, filectime($fileDir . $file));
}
}
2019-08-25 21:45:52 +02:00
}
if (ini_get('zlib.output_compression')) {
2019-08-27 00:31:46 +02:00
ini_set('zlib.output_compression', 'Off');
2019-08-25 21:45:52 +02:00
}
$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");
2019-08-27 00:31:46 +02:00
header("Content-Length: " . $length);
2019-08-25 21:45:52 +02:00
echo $zipData;
rrmdir(__DIR__ . '/xml');
2019-08-25 21:45:52 +02:00