I have file on my website transferred from other server.
Backup has .sql.gz format, when I download file via php code they do not work. Files are download but corrupted. I am on windows pc whereas its works on linux
Please help me out how can I make them work on windows too, I am using the following code:
$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);
This is the code I use to pass a file through 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
");
header("Pragma: hack
");
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: " . mime_content_type($file_path) . "
");
header("Content-Length: " . filesize($file_path) . "
");
$file_name = pathinfo($file_path);
header("Content-Disposition: attachment; filename=\"" . $file_name['basename'] . "\"
");
header("Content-Transfer-Encoding: binary");
if ($fp=fopen($file_path, "r")){
fpassthru($fp);
}
?>