Issue
I used BinaryFileResponse class to create download file response. file is a zip file. file checksum is different after file being downloaded. why this happens and can we send the original file as response.
$response = new BinaryFileResponse($filePath);
$response->headers->set('Content-Type', 'application/octet-stream');
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$fileName
);
return $response->send();
Solution
If you are in a controller, ->send()
is not needed ...
Your code should be ...
<?php
class MyController
{
public function action()
{
$response = new BinaryFileResponse($filePath);
$response->headers->set('Content-Type', 'application/octet-stream');
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
$fileName
);
return $response;
}
}
Answered By - SilvioQ Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.