Home > Backend Development > PHP Tutorial > 谁能解释下这个下载

谁能解释下这个下载

WBOY
Release: 2016-06-23 13:47:25
Original
1143 people have browsed it

if(is_file($file)) {
            header("Content-Type: application/force-download");
            header("Content-Disposition: attachment; filename=".basename($file));
            readfile($file);
            exit;
        }else{
            echo "文件不存在!";
            exit;
        }


application/force-download是什么
Content-Disposition: attachment是什么  filename是什么 readfile是什么


回复讨论(解决方案)

application/force-download 是一种 mime 类型,用于告知接收方:这是一个文件下载

Content-disposition 是 mime 协议的扩展
Content-Disposition: attachment 告知接收方:后面的 filename 属性是参考文件名
通常浏览器会弹出一个下载对话框,并显示文件名

readfile 是 php 函数
从函数名上就可看出他的功能 读(read)文件(file)

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template