0

我有一个 PHP 文件来强制下载 PDF 文件,在一台服务器(linux)上它运行良好,但是当我将站点移动到另一台服务器(Win)时,它开始出现此错误:

PHP Warning:  readfile(./forms/Form.pdf)
[<a href='function.readfile'>function.readfile</a>]:
failed to open stream: No such file or directory in
D:\CustomerData\webspaces\webspace\wwwroot\Form.php
on line 4

PHP文件有这个:

<?php
header('Content-disposition: attachment; filename=./forms/Form.pdf');
header('Content-type: application/pdf');
readfile('./forms/Form.pdf');
?>

谢谢!

4

1 回答 1

0

尝试使用绝对文件位置。我认为这个错误是因为文件路径

试试下面的代码。

$file = <absolute file path>;
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename='.basename($file));
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($file));
print_r(headers_list());
readfile($file);
于 2012-07-31T09:55:50.333 回答