Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-13 12:16:14
Original
819 people have browsed it

复制代码 代码如下:


/********************
*@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函数代码
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template