标题用于下载文件php [英] Headers used to download file php

查看:126
本文介绍了标题用于下载文件php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

php,文件下载

我的文件不在网络根目录我需要提供下载。所以我有一个使用下面的脚本来下载所请求的文件。问题是,我每个下载的文件是否已损坏?文件是确定的,因为如果我使用FTP下载,他们打开。以下是传递的标题:

I have files that are not in the web root that I need to make available for download. So I have a script that uses the below to download the file requested. The problem is, I everyfile downloaded is corrupt? The files are ok because if I use FTP to download, they open. Here are the headers passed:

header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
        header("Cache-Control: public"); // needed for i.e.
        header("Content-Type: " . $download[0]['mime']);
        header("Content-Disposition: attachment; filename=" .$download_file);
        header("Content-Transfer-Encoding: Binary");
        header("Content-Length:".filesize($attachment_location));

        readfile($attachment_location);


推荐答案

这是一个用于此的标题的示例: br>
http://php.net/manual/en/function.readfile.php

Here is an example of headers used for that:
http://php.net/manual/en/function.readfile.php

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));

这篇关于标题用于下载文件php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆