问题
I want to add a method to my platform that allows users to download all the files from an application, that will be zipped-up. Each application consists of multiple files that are stored in separate rows of the files-table in the database.
I tried many options, but just can't seem to add the actual files to the zip.
This is my code so far:
$sql = "SELECT * FROM files WHERE applications_id = :applications_id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':applications_id', $applications_id, PDO::PARAM_INT);
$stmt->execute();
$items = $stmt->fetchAll();
$zipfilename = 'temp_' . time() . '.zip';
$zip = new ZipArchive;
$zip->open($zipfilename, ZipArchive::CREATE);
foreach ($items as $item) {
//$zip->addFromString($item['filename'],$item['filename']);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipfilename);
header('Content-Length: ' . filesize($zipfilename));
readfile($zipfilename);
exit();
Any help would be greatly appreciated!
来源:https://stackoverflow.com/questions/34205913/force-download-multiple-blob-files-in-php