use http foundation to create content-disposition headers.
This commit is contained in:
parent
8e80756b08
commit
2276c6705c
|
@ -1,5 +1,6 @@
|
||||||
<?php namespace Laravel;
|
<?php namespace Laravel;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
|
||||||
use Symfony\Component\HttpFoundation\Response as FoundationResponse;
|
use Symfony\Component\HttpFoundation\Response as FoundationResponse;
|
||||||
|
|
||||||
class Response {
|
class Response {
|
||||||
|
@ -121,10 +122,12 @@ public static function download($path, $name = null, $headers = array())
|
||||||
{
|
{
|
||||||
if (is_null($name)) $name = basename($path);
|
if (is_null($name)) $name = basename($path);
|
||||||
|
|
||||||
|
// We'll set some sensible default headers, but merge the array given to
|
||||||
|
// us so that the developer has the chance to override any of these
|
||||||
|
// default headers with header values of their own liking.
|
||||||
$headers = array_merge(array(
|
$headers = array_merge(array(
|
||||||
'Content-Description' => 'File Transfer',
|
'Content-Description' => 'File Transfer',
|
||||||
'Content-Type' => File::mime(File::extension($path)),
|
'Content-Type' => File::mime(File::extension($path)),
|
||||||
'Content-Disposition' => 'attachment; filename="'.$name.'"',
|
|
||||||
'Content-Transfer-Encoding' => 'binary',
|
'Content-Transfer-Encoding' => 'binary',
|
||||||
'Expires' => 0,
|
'Expires' => 0,
|
||||||
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=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),
|
'Content-Length' => File::size($path),
|
||||||
), $headers);
|
), $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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue