Last active
August 29, 2015 14:00
-
-
Save bhowe/a47e62b0d7d35364edfc to your computer and use it in GitHub Desktop.
download word document docx headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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