Skip to content

Instantly share code, notes, and snippets.

@bhowe
Last active August 29, 2015 14:00
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 bhowe/a47e62b0d7d35364edfc to your computer and use it in GitHub Desktop.
Save bhowe/a47e62b0d7d35364edfc to your computer and use it in GitHub Desktop.
download word document docx headers
public function DownloadDocx()
{
$this->_extension = "docx";
$args = func_get_args();
$newName = trim($args[0]);
ob_flush();
if (!empty($newName)) {
$fileName =$_SERVER['DOCUMENT_ROOT'] . '/wills/docs/' .$newName;
} else {
throw new Exception("Invalid document name");
}
if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) {
header("Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document");
header("Content-Disposition: inline; filename=\"". $newName . '.' . $this->_extension."\"");
header("Content-Length: ".filesize($fileName . '.' . $this->_extension));
} else {
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=\"". $newName . '.' . $this->_extension."\"");
header("Content-Length: ".filesize($fileName . '.' . $this->_extension));
}
header("Expires: Fri, 01 Jan 2010 05:00:00 GMT");
if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) {
header("Cache-Control: no-cache");
header("Pragma: no-cache");
}
readfile($fileName . '.' . $this->_extension);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment