2012-07-31 6 views
0

PDF 파일을 강제로 다운로드하는 PHP 파일이 있는데, 한 서버 (Linux)에서 제대로 작동했지만 다른 서버 (Win)로 이동하면이 오류가 발생했습니다.PHP가 PDF를 다운로드 할 때 오류가 발생합니다.

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

아마도 'filename = ../forms/Form.pdf'? – k102

+0

백 슬래시 대 (슬래시) 대 슬래시일까요? – Nanne

+0

파일이 froms 경로에 존재하지 않거나 웹 서버 ID에 경로에 대한 권한이없는 것일 수 있습니다. 양식의 절대 경로를 사용하려고 시도 했습니까? 오류가 지속됩니까? – Hinek

답변

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); 
+0

'Content-length' 헤더를 설정할 때주의하십시오. HTTP 압축과 함께 사용하면 과거에 문제가있었습니다. – Matthew

+0

아니, 여전히 작동하지 않지만 감사합니다. – acidking

관련 문제