当前位置:首页 > PHP教程 > PHP高级教程

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";
}
}

这里是摘自硕编程之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的php函数代码
【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!