Commit f044b429 authored by Taylor Otwell's avatar Taylor Otwell

improved comments to download class.

parent ebf89b72
...@@ -101,7 +101,8 @@ class Download { ...@@ -101,7 +101,8 @@ class Download {
); );
/** /**
* Create a download response. * Create a download response. The proper headers will be sent
* to the browser to force the file to be downloaded.
* *
* @param string $path * @param string $path
* @param string $name * @param string $name
...@@ -109,22 +110,23 @@ class Download { ...@@ -109,22 +110,23 @@ class Download {
*/ */
public static function file($path, $name = null) public static function file($path, $name = null)
{ {
// -----------------------------------------------------
// If no filename was given, use the path basename.
// -----------------------------------------------------
if (is_null($name)) if (is_null($name))
{ {
$name = basename($path); $name = basename($path);
} }
return Response::make(file_get_contents($path))->header('Content-Description', 'File Transfer') $response = Response::make(file_get_contents($path));
->header('Content-Type', static::mime(pathinfo($path, PATHINFO_EXTENSION)))
->header('Content-Disposition', 'attachment; filename="'.$name.'"') $response->header('Content-Description', 'File Transfer');
->header('Content-Transfer-Encoding', 'binary') $response->header('Content-Type', static::mime(pathinfo($path, PATHINFO_EXTENSION)));
->header('Expires', 0) $response->header('Content-Disposition', 'attachment; filename="'.$name.'"');
->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') $response->header('Content-Transfer-Encoding', 'binary');
->header('Pragma', 'public') $response->header('Expires', 0);
->header('Content-Length', filesize($path)); $response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$response->header('Pragma', 'public');
$response->header('Content-Length', filesize($path));
return $response;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment