Download file using \Symfony\Component\HttpFoundation\Response

See BT#12723
pull/2487/head
jmontoyaa 8 years ago
parent 3fd96c6b17
commit fd6f9c12a0
  1. 12
      plugin/studentfollowup/post.php

@ -70,7 +70,17 @@ if ($post) {
); );
$filesystem = new Filesystem($adapter); $filesystem = new Filesystem($adapter);
if ($filesystem->has($attachmentUrlData['path'])) { if ($filesystem->has($attachmentUrlData['path'])) {
echo $filesystem->get($attachmentUrlData['path']); $contentType = DocumentManager::file_get_mime_type($attachmentUrlData['path']);
$response = new \Symfony\Component\HttpFoundation\Response();
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', $contentType);
$response->headers->set('Content-Disposition', 'attachment; filename="'.basename($attachmentUrlData['path']) . '";');
//$response->headers->set('Content-length', filesize($filename));
// Send headers before outputting anything
$response->sendHeaders();
$response->setContent($filesystem->read($attachmentUrlData['path']));
$response->send();
exit;
} else { } else {
api_not_allowed(true); api_not_allowed(true);
} }

Loading…
Cancel
Save