Solved

PDF corruption after download with PHP

Posted on 2013-05-28
2
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

752 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