PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 11, 2022

[FIXED] when BinaryFileResponse is used file checksum changes

 May 11, 2022     file, php, symfony     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing