您的位置:首页 > 编程语言 > PHP开发

PHP 强制性文件下载功能的函数代码(任意文件格式)

2010-05-26 00:00 891 查看
/******************** 
*@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"; 
} 
}

这里是摘自脚本之家之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: