<?php
$app -> get ( '/download/{id}' , function ( $request , $response , $args ) {
$this -> logger -> info ( "Загрузка файла" ) ;
$fileModel = $this -> filesGW -> getFile ( $args [ 'id' ] ) ;
//XSendFile
$path = Helper:: getPathForFile ( $this -> settings [ 'uploadFolder' ] , $fileModel ) ;
$response = $response -> withHeader ( 'X-SendFile' , realpath ( $path ) ) ; $response = $response -> withHeader ( 'Content-Type' , 'application/octet-stream' ) ;
$response = $response -> withHeader ( 'Content-Disposition' , 'attachment; filename=' . basename ( $path ) ) ;
}
return $response ;
} ) -> setName ( 'download' ) ;
PD9waHAKCiRhcHAtPmdldCgnL2Rvd25sb2FkL3tpZH0nLCBmdW5jdGlvbiAoJHJlcXVlc3QsICRyZXNwb25zZSwgJGFyZ3MpIHsKICAgICR0aGlzLT5sb2dnZXItPmluZm8oItCX0LDQs9GA0YPQt9C60LAg0YTQsNC50LvQsCIpOwoKICAgICRmaWxlTW9kZWw9JHRoaXMtPmZpbGVzR1ctPmdldEZpbGUoJGFyZ3NbJ2lkJ10pOwoKICAgIC8vWFNlbmRGaWxlCiAgICAkcGF0aD1IZWxwZXI6OmdldFBhdGhGb3JGaWxlKCR0aGlzLT5zZXR0aW5nc1sndXBsb2FkRm9sZGVyJ10sJGZpbGVNb2RlbCk7CiAgICBpZiAoZmlsZV9leGlzdHMoJHBhdGgpKSB7CiAgICAgICAgJHJlc3BvbnNlID0gJHJlc3BvbnNlLT53aXRoSGVhZGVyKCdYLVNlbmRGaWxlJywgcmVhbHBhdGgoJHBhdGgpKTsKICAgICAgICAkcmVzcG9uc2UgPSAkcmVzcG9uc2UtPndpdGhIZWFkZXIoJ0NvbnRlbnQtVHlwZScsJ2FwcGxpY2F0aW9uL29jdGV0LXN0cmVhbScpOwogICAgICAgICRyZXNwb25zZSA9ICRyZXNwb25zZS0+d2l0aEhlYWRlcignQ29udGVudC1EaXNwb3NpdGlvbicsJ2F0dGFjaG1lbnQ7IGZpbGVuYW1lPScgLiBiYXNlbmFtZSgkcGF0aCkpOwoKCiAgICB9CgogICAgcmV0dXJuICRyZXNwb25zZTsKfSktPnNldE5hbWUoJ2Rvd25sb2FkJyk7