1// Generate response
2$response = new Response();
3$filename = 'yourFileName.txt';
4
5// Set headers
6$response->headers->set('Cache-Control', 'private');
7$response->headers->set('Content-type', $yourMimeType );
8$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '";');
9$response->headers->set('Content-length', strlen($yourContentString));
10
11// Send headers before outputting anything
12$response->sendHeaders();
13
14// Send content
15$response->setContent( $yourContentString );
16
17return $response;
18