pixel-icon-web/download.php

67 lines
1.9 KiB
PHP

<?php
if (empty($_GET['icon']) || !preg_match("/^\w+(\.svg)?$/", $_GET['icon'])) exit;
$request = $_GET['icon'];
$icons_path = __DIR__."/icons";
if ($request == 'all') {
$mtime = filemtime(__DIR__.'/assets/index.js');
$zip_filename = "pixel-icons-$mtime.zip";
$zip_path = __DIR__."/zipped/$zip_filename";
if (!is_file($zip_path)) {
$zip = new ZipArchive();
if ($zip->open($zip_path, ZipArchive::CREATE) === TRUE) {
$files = scandir($icons_path);
foreach ($files as $file) {
$file_path = $icons_path."/$file";
if (substr($file, -4, 4) == ".svg") {
touch($file_path);
$zip->addFile($file_path, $file);
}
}
$zip->close();
} else {
echo "Oops";
exit;
}
}
if (is_file($zip_path)) {
header('Content-Type: application/zip');
$quoted = sprintf('"%s"', addcslashes(basename($zip_path), '"\\'));
$size = filesize($zip_path);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile($zip_path);
}
} else {
$file = $icons_path . "/$request";
if (!is_file($file)) exit;
header('Content-Type: image/svg+xml');
$quoted = sprintf('"%s"', addcslashes(basename($file), '"\\'));
$size = filesize($file);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $quoted);
header('Content-Transfer-Encoding: binary');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . $size);
readfile($file);
}