Skip to content

Instantly share code, notes, and snippets.

@Werninator
Created July 1, 2015 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Werninator/8c31374b764fea2b534f to your computer and use it in GitHub Desktop.
Save Werninator/8c31374b764fea2b534f to your computer and use it in GitHub Desktop.
Forced Downloads mit PHP
<?php
$filename = 'mein-export.csv';
$content = '1,2,3,4,5';
// Header setzen
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\";" );
header("Content-Transfer-Encoding: binary");
// Content ausgeben
echo $content;
// Wichtig: die() - sonst gibt's ne Weiterleitung.
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment