php newby

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomass
Forum Newbie
Posts: 1
Joined: Thu Oct 14, 2004 11:16 am

php newby

Post by tomass »

ok, i need to create a series of pages, the first contains a series of links to files, pdf or doc. once one of these is clicked i need a form to appear, the user inputs name and email. then on submit the form is posted and the file previously clicked starts downloading. i know the html, its the php im not sure of.

i assume i need to send a file id somehow to the form, then use form submit button to both send the form and download the file. but i am only guessing. all help much appreciated. im currently trawling through online tutorials
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

When the user inputs their name and email you should use a backend which uses something like $_POST['htmlelement'] to grab the element values, (where htmlelement is the name of the text field in question). There is other ways to do this but the option I have just given is about the easiest way. As for the file download, you should use header() to force a download. Something along the lines of:

Code: Select all

<?php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="filedownloaded.pdf"');

readfile('file.pdf');
?>
Post Reply