2

当我下载以 0kb 保存的任何文件时,下载脚本出现问题。有任何想法吗?这是我的 PHP 脚本

<?php
$file = $_GET['fname'];
$fullpath = get_bloginfo('template_url')."/application/display/1358947404.pdf";
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fullpath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
ob_clean();
flush();
readfile($fullpath);
?>
4

2 回答 2

1

请同时添加内容长度标头。

请试试这个: -

<?php
$file = $_GET['fname'];

$fullpath = get_bloginfo('template_url')."/application/display/1358947404.pdf";

$headers = get_headers($fullpath, 1);// use file absolute path here
$fsize = $headers['Content-Length'];

header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fullpath));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header("Content-Length: " . $fsize);
ob_clean();
flush();
readfile($fullpath);
?>
于 2013-01-24T06:21:24.670 回答
0

试试下面的代码,希望对你有帮助。

我已经在我的本地主机中对此进行了测试。

$file = $_GET['fname'];

$fullpath = get_bloginfo('template_url')."/application/display/1358947404.pdf";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($fullpath));
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($fullpath));
ob_clean();
flush();
readfile($fullpath);
于 2013-01-24T06:30:32.163 回答