DeX Posted December 19, 2016 Share Posted December 19, 2016 I don't want my users to be able to load all PDF on my system so I verify them with a token and then load their PDF like so: if ($location) { header('Content-Type: application/pdf'); readfile($location); } The problem is when they right click it to save, it tries to save as pdf-loader.php instead of the quote-123.pdf filename. They're trying to save them as the quote numbers so they are easily matched up with each customer quote and they're not the most savvy computer users. Even when using the Chrome menus to select SAVE, it still tries to save the same way. Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted December 19, 2016 Solution Share Posted December 19, 2016 If you don't mind forcing a download instead of presenting it in the browser then you can do header('Content-Disposition: attachment; filename="quote-123.pdf"');Otherwise make the URL to the PDF be something that ends in /quote-123.pdf. You can use URL rewriting (nicer) or change your /path/to/script.php to be like /path/to/script.php/quote-123.pdf which should still invoke your PHP script (easier). 1 Quote Link to comment Share on other sites More sharing options...
kicken Posted December 20, 2016 Share Posted December 20, 2016 (edited) If you don't mind forcing a download instead of presenting it in the browser If you use inline instead of attachment it'll still display in the browser while also using the custom filename (in chrome and firefox at least). Edited December 20, 2016 by kicken 2 Quote Link to comment Share on other sites More sharing options...
requinix Posted December 20, 2016 Share Posted December 20, 2016 If you use inline instead of attachment it'll still display in the browser while also using the custom filename (in chrome and firefox at least).And saving uses the filename? Huh. Didn't know that. Quote Link to comment Share on other sites More sharing options...
DeX Posted December 20, 2016 Author Share Posted December 20, 2016 Thank you very much! I had to make a slight change, this is what ended up working. // set application type as PDF header('Content-Type: application/pdf'); // set file to display on screen with downloadable filename header('Content-Disposition: inline; filename="' . $filename . '"'); readfile($location); 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.