PHP (Symfony) check file download is finished

Is it possible to get callback or something back to server when download file is finished?
Im use symfony framework and force file download by BinaryFileResponse. But with this method it’s not possible.

I test other response StreamedResponse with setCallback function like this:

    $response = new StreamedResponse();
    $response->setCallback(function () use ($fullName) {
        $handle = fopen($fullName, 'r');
        while (!feof($handle)) {
            $buffer = fread($handle, 1024);
            echo $buffer;ob_flush();
    $filename = "Data.mp3";
    $contentDisposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
    $response->headers->set('Content-Type', 'application/octet-stream');
    $response->headers->set('Content-Disposition', $contentDisposition);
    return $response;

But it still don’t work. My var_dump does not exist.
Do you know how to check the file is finished download by user?

Btw. How popular file hosting website detect how many MB/GB of bandwidth downloaded by users.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *