I have a form with the submit button. And I have a file in '/sites/default/files/tmp/my_doc.docx' I'm trying to download the file upon submitting the form.
Here is my code
public function submitForm(array &$form, FormStateInterface $form_state){
$filename = '/sites/default/files/tmp/my_doc.docx';
$response = new BinaryFileResponse($filename);
$form_state->setResponse($response);
}
But it doesnt't work properly.
That is, the file is being downloaded but has the same name that name of php file containing this code.
Could you clarify me, what have I done wrong ?