I've got a site with a table and want to add a button in front of each tr
. Clicking on the button should pop up the download dialog (save file) and after pushing "save", download the file.
I see this so often, and still don't know how to do that. I have set up the button via a form:
<form method="get">
<input type="submit" value="<?php echo $paket; ?>" name="download" />
</form>
where $paket
contains the filename without the .zip
ending.
In the same php file, just under two require_once
statements, I did this:
if ( isset( $_GET['download'] ) ) {
$name = $_GET['download'];
header( 'Content-Disposition: attachment; filename = '.$name.'.zip' );
header( 'Content-type: application/zip' );
}
If I push the button, I get these errors:
Warning: Cannot modify header information - headers already sent by (output started at /is/lib/require.req:154)
I do know that the header information needs to sit on the very top, but how am I supposed to use functions I include with require_once
, if the require_once
comes a few lines after?
Is there a nice (and foolproof) tutorial that I just can't find?