首页 > 编程 > PHP > 正文

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

2019-11-22 01:09:59
字体:
来源:转载
供稿:网友
复制代码 代码如下:

/********************
*@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函数代码
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表