如何在php中压缩(大)文件

时间:2018-05-29 06:24:25

标签: php

如何在php中压缩大文件(300MB)。我有问题,当我点击按钮,几秒后网页浏览器返回“此网站无法到达”,但我的压缩文件的过程仍然有效,并且创建zip后它将只在文件夹中,它将无法下载

1 个答案:

答案 0 :(得分:0)

function createZip($zip, $dir, $listOFfiles)
{ 
    if (ob_get_level()) {
        ob_end_clean();
    }
    if (is_dir($dir)) {
        foreach ($listOFfiles as $key => $fileName) {
            if (is_file($dir . '/' . $fileName)) {
                if ($fileName != '' && $fileName != '.' && $fileName != '..') {
                    // the problem is here. browser gets bad response
                    // because this process takes long time                 
                        $zip->addFile($dir . '/' . $fileName, $fileName);
                        flush();
                }
            }
        }
        return true;
    }
    return false;
}
?>