2016-09-09 40 views
-1

我編寫備份數據庫的代碼。 當我試圖下載sql.gz格式的文件時,它下載成功,但我無法解壓縮。這表明我: -成功下載後無法解壓sql.gz

錯誤而加載存檔

而且它的每一個尺寸只顯示620bytes但原來的.sql文件大小時間發生較大(大於1 MB)

$path=$result_array['path']; 
    $filename = basename($path); 
    $full_path = base_url()."database_backup/"; 
    $len = filesize($full_path.$path); 
    header("Content-Encoding: binary"); 
    header("Content-Type: application/octet-stream"); 
    header("content-length: " . $len); 
    header("content-disposition: attachment; filename=" . $filename); 
    header("Expires: 0"); 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Cache-Control: private"); 
    header("Pragma: public"); 
    ob_clean(); 
    $fp=fopen($full_path, "r"); 
    fpassthru($fp); 
    exit; 

所以請幫我解決這個問題。

+0

請給我解決方案。 –

+0

'$ len = filesize($ full_path);'我認爲這行計算錯誤的大小。請調試大小 –

+0

大小是完全使用'$ len = filesize($ full_path);' –

回答

0

。在你的腳本一個壞的路徑中,這兩行代碼比較從你的問題:

$len = filesize($full_path.$path); 

和:

$fp=fopen($full_path, "r"); 

我認爲第二個應該是:

$fp=fopen($full_path . $path, "r"); 

但是,如果可以的話,用$ filename替換$ path以避免仲裁文件泄露($ path可能是l ike「../../../../../../etc/passwd」)