How to download a page in pdf in php






















The only browser I tested that didn't force download is IE PS: and obviously run some sanity checks on the "file" variable to prevent people from stealing your files such as don't accept file extensions, deny slashes, add.

Don't loop through every file line. Use readfile instead, its faster. Instead of using a PHP script, to read and flush the file, it's more neat to rewrite the header using. This will keep a "nice" URL myfile. To make this more robust you could add HTML5 feature detection and if it's not there then use window. Here's a different approach. I prefer rather than to rely on browser support, or address this at the application layer, to use web server logic.

If you are using Apache, and can put an. Of course, you could put this in httpd. The FilesMatch directive is just a regex so it could be set as granularly as you want, or you could add in other extensions. The Header line does the same thing as the first line in the PHP scripts above.

If you need to set the Content-Type lines as well, you could do so in the same manner, but I haven't found that necessary. For more information click here. In a Ruby on Rails application especially with something like the Prawn gem and the Prawnto Rails plugin , you can accomplish this a little more simply than a full on script like the previous PHP example.

How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Craig Traynor Craig Traynor 2 2 gold badges 5 5 silver badges 15 15 bronze badges. Wrapping an input tag in a link tag is odd — Ben. Most likely something is causing the output to include some invalid pdf content..

Try to open the result file in a text editor — Ben. Ahh i hadnt noticed that, I had done that for another link but didnt notice i still had that — Craig Traynor. Have you tried to compare source and downloaded files? Make sure there's no trailing spaces after the? In fact, eliminate the? Add a comment. Active Oldest Votes. Mohammad Intsar Mohammad Intsar 4 4 silver badges 6 6 bronze badges. John Conde John Conde k 97 97 gold badges silver badges bronze badges.

Thats something I didnt know, i thought you always had to close them But it doesnt solve the problem unfortunately — Craig Traynor. Viewed 61k times. Kriem 8, 15 15 gold badges 70 70 silver badges bronze badges. Show 1 more comment. Active Oldest Votes. Goutam Pal Goutam Pal 1, 1 1 gold badge 10 10 silver badges 14 14 bronze badges.

Both links are dead. This is a good example why link only answer are BAD. Someone must have seen your comments. Both links are active now.

Add a comment. Here's an example and try this after configuring the above on your code. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Email Required, but never shown.

The Overflow Blog. Podcast what if you could invest in your favorite developer? Who owns this outage? Building intelligent escalation chains for modern SRE. Featured on Meta. Now live: A fully responsive profile. Reducing the weight of our footer. Linked 0. Related Hot Network Questions.



0コメント

  • 1000 / 1000