Skip to content

Instantly share code, notes, and snippets.

@nickweavers
Created April 2, 2014 18:38
Show Gist options
  • Save nickweavers/9940340 to your computer and use it in GitHub Desktop.
Save nickweavers/9940340 to your computer and use it in GitHub Desktop.
A view/tmpl file to show send a files contents to the browser with appropriate headers
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
header("Cache- Control: no-cache, must-revalidate" ); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$doc = $this->archivingModel->getFile($this->form_data['id_file']);
$file_type = $doc->content_type;
$content_body = $doc->content_body;
header("Content-Type: " . $file_type);
$output = fopen("php://output", "w");
if (fwrite($output, $content_body) === FALSE) {
$status = "* ERROR - Cannot write to php://output\n\n";
} else {
$status = "* File successfully written to php://output\n\n";
}
fclose($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment