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

yipeiwu_com6年前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.yipeiwu.com】之前发布的文章。更多的技巧可以参考。
收集的二十一个实用便利的PHP函数代码

相关文章

php线性表顺序存储实现代码(增删查改)

复制代码 代码如下: <?php /* *文件名:linearList.php * 功能:数据结构线性表的顺序存储实现 * author:黎锦焕 * @copyright:www....

PHP实现链表的定义与反转功能示例

本文实例讲述了PHP实现链表的定义与反转功能。分享给大家供大家参考,具体如下: PHP定义链表及添加、移除、遍历等操作: <?php class Node { pr...

phpstrom使用xdebug配置方法

1 到 http://xdebug.org/download.php下载xdebug。注意找到自己对应的php版本。或者可以通过 http://xdebug.org/wizard.php...

PHP新手NOTICE错误常见解决方法

刚学习PHP,不久,一般就看看手册,和一本叫PHP和mysql web开发的。 最近在整留言板,刚才遇到个问题。 页面中,好多类似 Notice: Use of undefined co...

php中利用post传递字符串重定向的实现代码

复制代码 代码如下: $ch = curl_init('http://domain-name.com/page.php');       curl_seto...