Solved

PDF corruption after download with PHP

Posted on 2013-05-28
2
385 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
Comment Utility
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
Comment Utility
Perfect.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 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

7 Experts available now in Live!

Get 1:1 Help Now