note 107581 added to function.header
| From: | info at kenovate dot com | Date: | Sun, 19 Feb 2012 10:25:44 +0000 |
| Subject: | note 107581 added to function.header | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186221@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:
$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
----
Server IP: 69.147.83.197
Probable Submitter: 122.161.63.155
----
Manual Page -- http://www.php.net/manual/en/function.header.php
Edit -- https://master.php.net/note/edit/107581
Del: integrated -- https://master.php.net/note/delete/107581/integrated
Del: useless -- https://master.php.net/note/delete/107581/useless
Del: bad code -- https://master.php.net/note/delete/107581/bad+code
Del: spam -- https://master.php.net/note/delete/107581/spam
Del: non-english -- https://master.php.net/note/delete/107581/non-english
Del: in docs -- https://master.php.net/note/delete/107581/in+docs
Del: other reasons-- https://master.php.net/note/delete/107581
Reject -- https://master.php.net/note/reject/107581
Search -- https://master.php.net/manage/user-notes.php