jasonc Posted October 6, 2009 Share Posted October 6, 2009 taken the following code from the php.net site the script is not working. what is not happening is the file does not show and also the file download does not show the correct file name it seems to have the file name but has replaced the / with an underscore. <? $PDFtoview = "minutes/PDF filename.pdf"; // outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="' . $PDFtoview . '"'); // The PDF source is in original.pdf readfile("'" . $PDFtoview . "'"); //echo($siteurl.$filename); } ?> Quote Link to comment Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 The value for the filename should be just that, a file name (not a path). It should be just "PDF filename.pdf" The readfile function expects its parameter to be the path to a file, yet you wrap that path in single quotes. The result is not a valid path so no file can be read. P.S. You state that the code was from php.net, could you link me to the exact page where you got the code from? Quote Link to comment Share on other sites More sharing options...
jasonc Posted October 6, 2009 Author Share Posted October 6, 2009 http://us2.php.net/manual/en/function.header.php Quote Link to comment Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 http://us2.php.net/manual/en/function.header.php Thanks, I thought there may have been a problem with the examples on that page. Quote Link to comment Share on other sites More sharing options...
jasonc Posted October 6, 2009 Author Share Posted October 6, 2009 i have checked and still the file is not showing or the download working Quote Link to comment Share on other sites More sharing options...
salathe Posted October 6, 2009 Share Posted October 6, 2009 Show us your changed code, and are you absolutely, 100% sure that a file exists called "PDF filename.pdf" in the directory "minutes" under the script's location? Quote Link to comment Share on other sites More sharing options...
jasonc Posted October 6, 2009 Author Share Posted October 6, 2009 ok the file now shows correctly in the browser. but the download link does not work. i use the index.php?file=123 method and the script would put the correct file in the header to be downloaded. i am still unsure what line (header) does what... <? $uploaddir = "/home/site/public_html/"; $PDFdoc = "PDF filename.pdf"; $PDFtoview = "folder/" . $PDFdoc; // outputting a PDF header('Content-type: application/pdf'); // It will be called downloaded.pdf header('Content-Disposition: attachment; filename="' . $PDFdoc . '"'); // The PDF source is in original.pdf readfile("'" . $uploaddir . $PDFtoview . "'"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" > <head> Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted October 6, 2009 Share Posted October 6, 2009 1) The readfile should just be: readfile($uploaddir . $PDFtoview); 2) It'll not work with all the HTML stuff below. Quote Link to comment Share on other sites More sharing options...
jasonc Posted October 6, 2009 Author Share Posted October 6, 2009 ok that works now, thanks. this has been beating me up for days as to why it is shown on the php.net site that it needs the ' but it works without them! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.