下载.sql.gz文件


Download .sql.gz file

我的网站上有从其他服务器传输的文件。

备份具有.sql.gz格式,当我通过php代码下载文件时,它们不起作用。文件已下载但已损坏。我在Windows PC上,而它在Linux上工作

请帮助我如何使它们也能在Windows上运行,我正在使用以下代码:

$fileurl=$path."/mysql/03/mydb1.sql.bz2";
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Description: Download SQL Export");                 
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename=test.sql.bz2');
header('Content-Length: ' . filesize($fileurl));
readfile($fileurl);

这是我用来通过 PHP 传递文件的代码。

<?php
    // replacement function for mime type
    if (!function_exists('mime_content_type')){
        function mime_content_type($file){
            ob_start();
            system('/usr/bin/file -i -b "' . realpath($file). '"');
            $type = ob_get_clean();
            $parts = explode(';', $type);
            return trim($parts[0]);
        }
    }
    //
    $file_path = '/your/file/path/here.gz';
    //
    header("Cache-Control: public, must-revalidate'n");
    header("Pragma: hack'n");
    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'n");
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Content-Type: " . mime_content_type($file_path) . "'n");
    header("Content-Length: " . filesize($file_path) . "'n");
    $file_name = pathinfo($file_path);
    header("Content-Disposition: attachment; filename='"" . $file_name['basename'] . "'"'n");
    header("Content-Transfer-Encoding: binary");
    if ($fp=fopen($file_path, "r")){ 
        fpassthru($fp);
    }
?>