Tạo link tải file zip

Post Reply
tthlan
Quản trị viên
Posts: 76
Joined: Tue Aug 23, 2016 8:13 am

Tạo link tải file zip

Post by tthlan »

Code: Select all

$zip_file_name = '../pdf/KyujinDetailRodoJoukenAll.zip'; 
$zip = new ZipArchive();
$res = $zip->open($zip_file_name, ZipArchive::CREATE | ZipArchive::OVERWRITE)
// foreach (...) {
   $zip->addFile('../pdf/' . $kyujin_id . '.pdf', $kyujin_id . '.pdf');
//}
$zip->close();

  $save_file = 'KyujinDetailRodoJoukenAll.zip';
// Force download
header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".$save_file);
ob_end_clean();
readfile($zip_file_name);

// Remove export zip file
if (file_exists($zip_file_name)) {
   unlink($zip_file_name);
}
exit;
Post Reply