/********************
*@file - path to file
*/
function force_download($file)
{
if ((isset($file))&&(file_exists($file))) {
header("Content-length: ".filesize($file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$file");
} else {
echo "No file selected";
}
}
Article Detail
PHP 强制性文件下载功能的函数代码(任意文件格式)
/******************** *@file - path to file */ function force_download($file) { ...