jho*_*on4 2 php header download
可能重复:
php,文件下载
我有不在Web根目录中的文件,我需要提供下载.所以我有一个脚本,使用下面的代码来下载所请求的文件.问题是,我下载的每个文件都已损坏?文件没问题,因为如果我使用FTP下载,它们会打开.这是传递的标题:
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);
Run Code Online (Sandbox Code Playgroud)
Alm*_*čić 10
以下是用于此的标头示例: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));
Run Code Online (Sandbox Code Playgroud)