Laravel\Lumen\Http\ResponseFactory::download PHP Method

download() public method

Create a new file download response.
public download ( SplFileInfo | string $file, string $name = null, array $headers = [], null | string $disposition = 'attachment' ) : BinaryFileResponse
$file SplFileInfo | string
$name string
$headers array
$disposition null | string
return Symfony\Component\HttpFoundation\BinaryFileResponse
    public function download($file, $name = null, array $headers = [], $disposition = 'attachment')
    {
        $response = new BinaryFileResponse($file, 200, $headers, true, $disposition);
        if (!is_null($name)) {
            return $response->setContentDisposition($disposition, $name, str_replace('%', '', Str::ascii($name)));
        }
        return $response;
    }

Usage Example

 public function testDownloadDefaultResponse()
 {
     $temp = tempnam(sys_get_temp_dir(), 'fixture');
     $fh = fopen($temp, 'w+');
     fwrite($fh, 'writing to tempfile');
     fclose($fh);
     $responseFactory = new ResponseFactory();
     $response = $responseFactory->download($temp);
     $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $response);
     $this->assertEquals(false, $response->getContent());
     $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
     unlink($temp);
 }