2

I'm sending files in action helper for downloads (in parts if needed) like this:

...
$response->sendHeaders();

$chunksize = 1 * (1024 * 1024);
$bytesSent = 0;

if ($httpRange) {
    fseek($file, $range);
}

while(!feof($file) &&
   (!connection_aborted() &&
   ($bytesSent < $newLength))
) {
    $buffer = fread($file, $chunksize);
//      $response->appendBody($buffer); // this would be better
    print($buffer);
    flush();
    $bytesSent += strlen($buffer);
}
fclose($file);

I suspect that better way would be to make use of $response object instead of print.

Which is the recommended way to send big response objects using Zend Framework?

takeshin
  • 49,108
  • 32
  • 120
  • 164

1 Answers1

0

Usually I use Noginn Action Helper to send file for downloads. Here is a good description in another answer: How to add a third-party Action Helper to a Zend Framework 1.8+ application?

Url to SendFile.php: https://github.com/noginn/noginn/blob/master/Noginn/Controller/Action/Helper/SendFile.php

Community
  • 1
  • 1
ksimon
  • 711
  • 11
  • 24