【问题标题】:ZipStream and Kohana 3.3ZipStream 和 Kohana 3.3
【发布时间】:2013-10-18 19:20:41
【问题描述】:

我正在尝试使用 ZipStream (https://github.com/Grandt/PHPZip) 在 Kohana 3.3 中动态创建和流式传输 zip 文件。我以为只要将第一个图像添加到 zip 中,就会流式传输 zip 文件,但碰巧下载会停止,直到创建整个 zip 文件并将其发送给用户。

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Download extends Controller {
    public function action_images()
    {
        require Kohana::find_file('vendor', 'ZipStream');
        $zip = new ZipStream("images.zip");
        foreach($images as $image)
        {
            $zip->addLargeFile($image);
        }
        $zip->finalize();
        exit;
    }
}

【问题讨论】:

    标签: kohana


    【解决方案1】:

    显然 Kohana 缓冲输出,可以通过将其添加到下载操作来否定。

    while (ob_get_level() > 0) {
        ob_end_clean();
    }
    

    整个控制器

    <?php defined('SYSPATH') or die('No direct script access.');
    
        class Controller_Download extends Controller {
            public function action_images()
            {
                while (ob_get_level() > 0) {
                    ob_end_clean();
                }
                require Kohana::find_file('vendor', 'ZipStream');
                $zip = new ZipStream("images.zip");
                foreach($images as $image)
                {
                    $zip->addLargeFile($image);
                }
                $zip->finalize();
                exit;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 2015-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多