PHP PDF code not working -



PHP PDF code not working -

i have section can download work related pdfs. code works in localhost not on live site. ideas happened?

<div id="resources"> <h1>pilot auto resources</h1> <table style="width:400px" id="resourcestable"> <tr> <td>kansas handbook</td> <td><a href="?file=kansashandbook.pdf">download pdf file</a></td> </tr> <tr> <td>ga amber lite application</td> <td><a href="?file=georgiaamberlightapplication.pdf">download pdf file</a></td> </tr> </table> </div>

and php

<?php if (isset($_get["file"]) && !empty($_get["file"])) { $file = $_get["file"]; $path = "/resources/"; $getfile = $path . $file; if (file_exists($getfile)) { header('content-description: file transfer'); header('content-type: application/octet-stream'); header("content-type: application/force-download"); header('content-disposition: attachment; filename=' . urlencode(basename($getfile))); // header('content-transfer-encoding: binary'); header('expires: 0'); header('cache-control: must-revalidate, post-check=0, pre-check=0'); header('pragma: public'); header('content-length: ' . filesize($getfile)); ob_clean(); flush(); readfile($getfile); exit; } } ?>

problem 1

you start at

http://jollyrogerpcs.com/index.php

hyperlinks on page href="file/?kansashandbook.pdf"

so file request to

http://jollyrogerpcs.com/index.php?file=kansashandbook.pdf

$_get['file'] ignored , html http://jollyrogerpcs.com/index.php delivered browser. why page refreshes when click download pdf link.

change links absolute links reference downloadpdf.php , file var.

e.g

http://jollyrogerpcs.com/scripts/php/downloadpdf.php?file=/kansashandbook.pdf

problem 2

it's hard tell without seeing more code, seem have have path related issue in downloadpdf.php. when request url, $getfile '/resources/kansashandbook.pdf'. believe readfile() seek search pdf in http://jollyrogerpcs.com/scripts/php/resources/kansashandbook.pdf.

you can troubleshoot playing around combination of absolute pathing or __dir__ magic constant.

php pdf localhost

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -