0

I have created downlaod() method to downloading zip file via browser, each of arround 500-1500 MG. All is fine when I donwload zip file e.g. with 50 MB. Problem is only with big files.

public function download($version) {

set_time_limit(0);
$file_name = $version . $this->extension;

$path = DOC_ROOT . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->folder_name . DIRECTORY_SEPARATOR . $file_name;

if(is_file($path) || connection_status() == 0)
{
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
    header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
    header("Content-Type: application/octet-stream");
    header("Content-Length: ".(string)(filesize($path)));
    header("Content-Disposition: inline; filename=$file_name");
    header("Content-Transfer-Encoding: binary\n");

    if ($file = fopen($path, 'rb')) {
        while(!feof($file)) {
            print fread($file,$this->transfer_speed);
            flush();
        }
        fclose($file);
    }
}

if(connection_status() !== CONNECTION_NORMAL)
{
    echo "Connection aborted";
}

return((connection_status()==0) && !connection_aborted());

}

Poniat
  • 31
  • 4
  • 2
    Possible duplicate of [using php to download files, not working on large files?](https://stackoverflow.com/questions/3176942/using-php-to-download-files-not-working-on-large-files) – rbaskam Oct 05 '17 at 14:52
  • I have managed to download big zip files. However, all of them return error when I try to unzip them: **The archive is either in unknown format or damanged**. – Poniat Oct 05 '17 at 15:37

0 Answers0