Php code
$file = get_file_address(); // The real address of the file (supports url, but url is not recommended)
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
Ob_clean(); //The important thing is the call of this function, clear but not close the output cache, otherwise the first two characters of the downloaded file will be 0a
flush();
Readfile($file); // Output file content
}
?>
-----------------------EOF------------------------
This article is from "pswzyu's technology blog"