PHP强制下载文件
2017-07-28 08:47
316 查看
header() 函数向客户端发送原始的 HTTP 报头。进入指定页面后就弹出文件下载对话框,如图
代码如下:
[php]
view plain
copy
function download_file($archivo, $downloadfilename = null) {
if (file_exists($archivo)) {
$downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $downloadfilename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($archivo));
ob_clean();
flush();
readfile($archivo);
exit;
}
}
代码如下:
[php]
view plain
copy
function download_file($archivo, $downloadfilename = null) {
if (file_exists($archivo)) {
$downloadfilename = $downloadfilename !== null ? $downloadfilename : basename($archivo);
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=' . $downloadfilename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($archivo));
ob_clean();
flush();
readfile($archivo);
exit;
}
}
相关文章推荐
- PHP强制下载PDF文件的例子
- php强制下载文件、文件强制下载、输出强制下载
- PHP强制下载文件
- PHP 强制下载文件代码
- IE php关于强制下载文件的代码
- 如何使用PHP来强制文件下载
- 怎样使用PHP来强制文件下载
- 强制文件下载php
- php下载文件源代码(强制任意文件格式下载)
- PHP强制下载文件
- 记录一个php强制下载文件函数
- PHP强制浏览器不打开而是下载文件
- php实现文件强制下载
- php进行文件的强制下载
- 使用PHP强制下载PDF文件示例
- [PHP实例] PHP 强制文件下载
- php简单实现文件或图片强制下载的方法
- PHP 实现文件强制下载
- 用php把强制下载各类文件的方法
- php 强制文件下载