views:

146

answers:

1

Hi,

I've implemented a download script using PHP headers to download PDF files. My script is working fine and downloading the corresponding PDF file also in my localhost but that script is not working in my server.

My code is:

header("Content-Disposition: attachment; filename='dfile.pdf'");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: application/pdf;");

readfile("http://www.education.gov.yk.ca/pdf/pdf-test.pdf");

In my server file browser is appearing fine and downloading the file also as dfile.pdf, but If I try to open the downloaded file then I'm getting an error message of the file has been damaged. Any of my server settings causing this issue or something else?

Any suggestion to fix this problem is much appreciable.

Note: I think this might be an issue with my server PHP settings, can anybody tell me whether the "readfile" function need any PHP setting to enable in my server?

Thanks in advance, Siva...

+1  A: 

I think PHP outputs some warning before PDF file body. Check that.

FractalizeR
I'm not able to open the downloaded PDF file. While opening the file I'm just getting an error popup with message of 'Adobe Reader could not open "dfile.pdf" because it is either not a supported file type or because the file has been damaged.
Siva
You can open it in any hex or text editor just to see if there any non-PDF things at the beginning.
FractalizeR
Yeah opened with text editor(word pad and text pad), nothing is appearing. Downloaded file is of '0 KB' size with no data.
Siva
So, the file is 0 Kbs? Check server log. Probably, there is some PHP error preventing file access (permissions for example).
FractalizeR
This issue is because of my server PHP settings, 'allow_url_fopen' setting is not enabled in my server. I'm handling this situation by using the CURL, anyway thanks for your suggestions.
Siva
So, anything in the log?
FractalizeR