From e2cdf434ba315009b3eb5f32509477020d814209 Mon Sep 17 00:00:00 2001 From: Julien Carignan Date: Mon, 24 Mar 2014 13:55:01 -0400 Subject: [PATCH] "php://output" content-length + tmpfile location - added content-length header to know the total file size during the download - Tmp file should go into sys_get_temp_dir() instead of "./" Signed-off-by: Julien Carignan --- Classes/PHPWord/Writer/Word2007.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Classes/PHPWord/Writer/Word2007.php b/Classes/PHPWord/Writer/Word2007.php index 16d66c66..2589e9ef 100755 --- a/Classes/PHPWord/Writer/Word2007.php +++ b/Classes/PHPWord/Writer/Word2007.php @@ -113,7 +113,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter // If $pFilename is php://output or php://stdout, make it a temporary file... $originalFilename = $pFilename; if (strtolower($pFilename) == 'php://output' || strtolower($pFilename) == 'php://stdout') { - $pFilename = @tempnam('./', 'phppttmp'); + $pFilename = @tempnam(sys_get_temp_dir(), 'phpword_');// temp files should go to system temp directory (if a user cancels a download, the file stays) if ($pFilename == '') { $pFilename = $originalFilename; } @@ -236,6 +236,7 @@ class PHPWord_Writer_Word2007 implements PHPWord_Writer_IWriter // If a temporary file was used, copy it to the correct file stream if ($originalFilename != $pFilename) { + header('Content-Length: '.filesize($pFilename));// if php://output, we want to know the total file size when downloading if (copy($pFilename, $originalFilename) === false) { throw new Exception("Could not copy temporary zip file $pFilename to $originalFilename."); }