Solved

PDF corruption after download with PHP

Posted on 2013-05-28
2
389 Views
Last Modified: 2013-05-28
I would like visitors to my website to be offered an easy way to download a pdf, rather than instructing them to right click and "save as".  I'm using the attached PHP code, which downloads the file to my desktop.  However, the downloaded version of the pdf is corrupt, 0 bytes, and can't be opened.  Please advise.  I have also tried removing the closing "?>".  The file is downloaded, but still corrupted. The PHP setting 'allow_url_fopen' setting isenabled in my server.    PDF-Downloader.php
0
Comment
Question by:ddantes
2 Comments
 
LVL 15

Accepted Solution

by:
Jagadishwor Dulal earned 500 total points
ID: 39200594
I think your problem is in this two lines

header('Content-disposition: attachment; filename=' . $pdf);
readfile('path_to_pdfs' . $pdf);

Open in new window


change second line to:
readfile($pdf);

Open in new window


Again I don't know what you are getting from
$pdf = substr($_SERVER['PATH_INFO'], 1);

Open in new window

0
 

Author Comment

by:ddantes
ID: 39200734
Perfect.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now