From 2276c6705c527984f45d110c1d7272a86dbe32e2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sun, 1 Apr 2012 23:19:45 -0500 Subject: [PATCH] use http foundation to create content-disposition headers. --- laravel/response.php | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/laravel/response.php b/laravel/response.php index 6f8c948a..f40d56f4 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -1,5 +1,6 @@ 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), - 'Content-Disposition' => 'attachment; filename="'.$name.'"', 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', @@ -132,7 +135,27 @@ public static function download($path, $name = null, $headers = array()) 'Content-Length' => File::size($path), ), $headers); - return new static(File::get($path), 200, $headers); + // Once we create the response, we need to set the content disposition + // header on the response based on the file's name. We'll pass this + // off to the HttpFoundation and let it create the header text. + $response = new static(File::get($path), 200, $headers); + + $d = $response->disposition($name); + + return $response->header('Content-Disposition', $d); + } + + /** + * Create the proper Content-Disposition header. + * + * @param string $file + * @return string + */ + public function disposition($file) + { + $type = ResponseHeaderBag::DISPOSITION_ATTACHMENT; + + return $this->foundation->headers->makeDisposition($type, $file); } /**