Yngvarr

Generation

generate functionSat, 07 Jan 2023

pack to gz and return archive file download

function pack_and_download($file){ // pack the file $gzfile = gzopen($file.".gz", "w9"); gzwrite($gzfile, file_get_contents($file)); gzclose($gzfile); // download the file header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'.gz"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file.".gz")); ob_clean(); flush(); readfile($file.".gz"); unlink($file.".gz"); exit; }

Questions about programming?Chat with your personal AI assistant