-
-
Save Xatenev/e96c34701633ce497bbdcb052163502f to your computer and use it in GitHub Desktop.
file.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function outputFileDownload($files, $articleFiles) { | |
$filePrefix = 'Downloads_-_'; | |
$zipname = "blc_files.zip"; | |
$zip = new ZipArchive(); | |
$zip->open($zipname, ZipArchive::CREATE); | |
foreach ($files as $fileName => $fileValue) { | |
$allowedDownload = false; | |
foreach ($articleFiles as $articleFile) { // Security check here because otherwise people could download all files from the whole wiki: only allow file downloads for files attached to downloads page | |
if ($filePrefix . $fileName == $articleFile->img_name) { | |
$allowedDownload = true; | |
} | |
} | |
if ($allowedDownload) { | |
$wfFile = wfFindFile($filePrefix . $fileName); | |
$zip->addFile($wfFile->getLocalRefPath(), $fileName); | |
} | |
} | |
$zip->close(); | |
header('Content-Type: application/zip'); | |
header('Content-disposition: attachment; filename=' . $zipname); | |
header('Content-Length: ' . filesize($zipname)); | |
readfile($zipname); | |
return unlink($zipname); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment