开发者

Sending multipart response for downloads in Zend Framework

开发者 https://www.devze.com 2022-12-27 21:52 出处:网络
开发者_高级运维I\'m sending files in action helper for downloads (in parts if needed) like this:
开发者_高级运维

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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号