Web applications that want to force a resource to be downloaded rather than directly rendered in a Web browser issue a Content-Disposition
hea
PHP framework Symfony 4 has $filenameFallback
in HeaderUtils::makeDisposition
.
You can look into this function for details - it is similar to the answers above.
Usage example:
$filenameFallback = preg_replace('#^.*\.#', md5($filename) . '.', $filename);
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, $filenameFallback);
$response->headers->set('Content-Disposition', $disposition);