From 3b73d44461869c3a8435c528e747ceb386e8edf1 Mon Sep 17 00:00:00 2001 From: Shuqi Date: Mon, 13 Nov 2023 03:44:51 +0800 Subject: [PATCH] Script for download --- download.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 download.php diff --git a/download.php b/download.php new file mode 100644 index 0000000..cd913d2 --- /dev/null +++ b/download.php @@ -0,0 +1,66 @@ +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); +}