Solved

PDF corruption after download with PHP

Posted on 2013-05-28
2
392 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

808 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