Yngvarr

Generation

generate functionSat, 07 Jan 2023

pack to gz and return archive file download

function pack_and_download($file){ $filename = $file->getClientOriginalName(); $tmpFile = tempnam(sys_get_temp_dir(), 'data'); $tmpFileHandle = fopen($tmpFile, 'w'); fwrite($tmpFileHandle, $file->get()); fclose($tmpFileHandle); $outputFile = tempnam(sys_get_temp_dir(), 'data') . ".gz"; $fp = gzopen($outputFile, 'wb9'); gzwrite($fp, file_get_contents($tmpFile)); gzclose($fp); $response = new Response(file_get_contents($outputFile), 200); $response->header('Content-Type', 'application/x-gzip'); $response->header('Content-Disposition', 'attachment; filename=' . $filename . '.gz'); return $response; }

Questions about programming?Chat with your personal AI assistant