Solved

PDF corruption after download with PHP

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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 look for a specific file type in a local or remote server directory using PHP.

756 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