簡體   English   中英

下載.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);
    }
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM