Created
June 28, 2018 11:03
-
-
Save v1talii-dev/a420d9166c98428d58337fedb9b76e3d to your computer and use it in GitHub Desktop.
D8: download binary file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Скачивание файла. | |
*/ | |
function downloadBinaryFile(File $file = NULL) { | |
if (empty($file)) { | |
return NULL; | |
} | |
$fileUri = $file->getFileUri(); | |
$headers = [ | |
'Content-disposition' => 'attachment; filename="' . $file->getFilename() . '"', | |
]; | |
return new BinaryFileResponse($fileUri, 200, $headers, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment