我有一个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');
?>
谢谢!
答案 0 :(得分: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);