/** * Create a new download response instance. * * <code> * // Create a download response to a given file * return Response::download('path/to/file.jpg'); * * // Create a download response with a given file name * return Response::download('path/to/file.jpg', 'your_file.jpg'); * </code> * * @param string $path * @param string $name * @param array $headers * @return Response */ public static function download($path, $name = null, $headers = array()) { 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('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path)), $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); }
public static function download($path, $name = null, $headers = array()) { if (is_null($name)) { $name = basename($path); } $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path)), $headers); $response = new static(File::get($path), 200, $headers); $d = $response->disposition($name); return $response->header('Content-Disposition', $d); }