note 107581 modified in function.header by danbrown

From: Date: Thu, 10 May 2012 20:42:16 +0000
Subject: note 107581 modified in function.header by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-187825@lists.php.net to get a copy of this message
To use header() with 'content-type', why don't you use mime_content_type() function rather than checking the type on the basis of extension?
Example code:

<?php
$file="test.docx";
header("Pragma: public");
header('Content-disposition: attachment; filename='.$file);
header("Content-type: ".mime_content_type($file));
header('Content-Transfer-Encoding: binary');
ob_clean(); 
flush(); 
readfile($file);
?>

Use $file to map to whichever type of file.
Note: the mime types should already be defined in apache settings --was-- To use header() with 'content-type', why don't you use mime_content_type() function rather than checking the type on the basis of extension? Example code: $file="test.docx"; header("Pragma: public"); header('Content-disposition: attachment; filename='.$file); header("Content-type: ".mime_content_type($file)); header('Content-Transfer-Encoding: binary'); ob_clean(); flush(); readfile($file); Use $file to map to whichever type of file. Note: the mime types should already be defined in apache settings http://php.net/manual/en/function.header.php

« previous php.notes (#187825) next »