咔叽游戏

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 108|回复: 0

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

[复制链接]

该用户从未签到

发表于 2019-10-9 17:10:41 | 显示全部楼层 |阅读模式
PHP强制性文件下载函数代码,使用此函数为用户提供强制性的文件下载功能。

/********************
*@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";
}
}

这里是摘自咔叽网单www.2nzz.com之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码

QQ|免责声明|小黑屋|手机版|Archiver|咔叽游戏

GMT+8, 2024-3-29 20:48

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表